System.Diagnostics.Debug.WriteLine("edited user is valid");
// Fetch the user object from the service and overwrite the properties from the updated object
// we got from the view.
User refreshedUser = DirectoryService.users.Where(it => (it.objectId == user.objectId)).SingleOrDefault();
System.Diagnostics.Debug.WriteLine("edited user is:" + refreshedUser.displayName);
// Save the changes to User object and then write the File stream
// for Thumbnail photo in case it has been updated by the user.
refreshedUser.userPrincipalName = string.Format(CultureInfo.InvariantCulture, "{0}@{1}", emailAlias, selectedDomain);
refreshedUser.mailNickname = emailAlias;
CopyPropertyValuesFromViewObject(user, refreshedUser);
DirectoryService.UpdateObject(refreshedUser);
System.Diagnostics.Debug.WriteLine("updated user is:" + refreshedUser.city);
DirectoryService.SaveChanges(SaveChangesOptions.PatchOnUpdate);
if (!String.IsNullOrEmpty(Request.Files[0].FileName))
{
// Write the photo file to the Graph service.
Debug.Assert(Request.Files.Keys[0] == "photofile");
DirectoryService.SetSaveStream(refreshedUser, "thumbnailPhoto", Request.Files["photofile"].InputStream, true, "image/jpg");
DirectoryService.SaveChanges(SaveChangesOptions.PatchOnUpdate);
}
return RedirectToAction("Index");
}