public PartialViewResult EditAccountDetails() { ProfileAccountDetailsViewModel lModel = new ProfileAccountDetailsViewModel(); lModel.FirstName = Runtime.Account.FirstName; lModel.LastName = Runtime.Account.LastName; lModel.Email = Runtime.Account.Email; return(PartialView(lModel)); }
public ActionResult EditAccountDetails(ProfileAccountDetailsViewModel model) { if (this.ModelState.IsValid) { using (ApplicationDbContext db = new ApplicationDbContext()) { Account lCurrentAccount = db.Account.Find(Runtime.Account.Id); lCurrentAccount.FirstName = model.FirstName; lCurrentAccount.LastName = model.LastName; if (model.ChangePassword != null) { String lNewPassword = Security.ByteArrayToHex(Security.SHACngHash(model.ChangePassword, 256), true); if (lNewPassword != model.ChangePassword) { lCurrentAccount.Password = lNewPassword; } } if (model.Email != Runtime.Account.Email) { Account lExistingAccount = db.Account.Where(x => x.Email == model.Email).FirstOrDefault(); if (lExistingAccount == null) { lCurrentAccount.Email = model.Email; } else { this.ModelState.AddModelError("Email", "Email already exists. Please use a different email."); } } if (this.ModelState.IsValid) { lCurrentAccount.LastModified = DateTime.UtcNow; db.SaveChanges(); } } } return(PartialView(model)); }