public ActionResult Create(UserProfile userprofile) { if (ModelState.IsValid) { try { WebSecurity.CreateUserAndAccount(userprofile.UserName, userprofile.Password); Roles.AddUserToRole(userprofile.UserName, "Administrator"); UserProfile ItmtoEdit = db.UserProfile.Where(p => p.UserName == userprofile.UserName).FirstOrDefault(); ItmtoEdit.FirstName = userprofile.FirstName; ItmtoEdit.LastName = userprofile.LastName; ItmtoEdit.Email = userprofile.Email; db.SaveChanges(); } catch (DbEntityValidationException e) { throw e; } return RedirectToAction("Index"); } return View(userprofile); }
public ActionResult Edit(UserProfile userprofile) { if (ModelState.IsValid) { if (userprofile.Password != null) { MembershipUser user; user = Membership.GetUser(userprofile.UserName, false); user.ChangePassword(user.ResetPassword(), "123456"); ViewBag.ErrorMessage = "Password Updated"; } db.Entry(userprofile).State = EntityState.Modified; db.SaveChanges(); } return View(userprofile); }