public ActionResult UserPropertiesList() { return Task.Run(async () => { var uservm = new UserPropertiesViewModel(); try { var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); uservm.UserName = user.UserName; uservm.Gender = user.Gender; uservm.State = user.State; uservm.FirstName = user.FirstName; uservm.LastName = user.LastName; uservm.EmailAddress = user.EmailAddress; uservm.Phone = user.Phone; //uservm.JoinDate = user.JoinDate; uservm.DateOfBirth = user.DateOfBirth; uservm.DateUserDetailsUpdated = DateTime.Now; if (user.Company == null || user.Company == "Not Listed") { uservm.Company = "Not Listed"; } else { uservm.Company = user.Company; } var currenddate = DateTime.Now; var userAge = currenddate.Year - user.DateOfBirth.Year; if (user.DateOfBirth > currenddate.AddYears(-userAge)) { userAge--; } uservm.Age = userAge; } catch (Exception ex) { Trace.TraceError("Error occurred while getting user properties: {0}", ex.ToString()); } return (ActionResult)PartialView("_UserSettingsPartial", uservm); }).Result; }
public async Task<ActionResult> UserProperties(UserPropertiesViewModel model) { if (ModelState.IsValid) { try { var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); user.FirstName = model.FirstName; user.LastName = model.LastName; user.EmailAddress = model.EmailAddress; user.Gender = model.Gender; user.DateOfBirth = model.DateOfBirth; user.State = model.State; user.Phone = model.Phone; user.Company = model.Company; await UserManager.UpdateAsync(user); return RedirectToAction("Manage", new { Message = "Your properties have been updated." }); } catch (Exception ex) { Trace.TraceError("Error occurred while updating user properties : {0}", ex.ToString()); } } return RedirectToAction("Manage", model); }