public ActionResult Edit(UsersEditViewModel model) { // Add Data Management evaluation section changes here. // End changes. // Solution: if (model.Id != 0) { EntityModels.AspNetUser user = db.AspNetUsers.FirstOrDefault(x => x.Id == model.Id); // Modifying password and roles. if (model.NewPassword != string.Empty) { user.PasswordHash = AuthController.EncodePasswordMd5(model.NewPassword); } if (model.UserRole != user.AspNetRoles.Id) { user.AspNetRoles = db.AspNetRoles.FirstOrDefault(x => x.Id == model.UserRole); //user.AspNetRoles.Name = model.UserRole.ToString(); } db.SaveChanges(); return(RedirectToAction("Edit", new { id = user.Id })); } else { EntityModels.AspNetUser user = new EntityModels.AspNetUser(); user = db.AspNetUsers.FirstOrDefault(x => x.Email == User.Identity.Name); // Modifying password and roles. if (model.NewPassword != string.Empty) { user.PasswordHash = AuthController.EncodePasswordMd5(model.NewPassword); } if (model.UserRole != user.AspNetRoles.Id) { user.AspNetRoles = db.AspNetRoles.FirstOrDefault(x => x.Id == model.UserRole); //user.AspNetRoles.Name = model.UserRole.ToString(); } db.SaveChanges(); return(RedirectToAction("Edit", new { id = user.Id })); } // End solution. }
public ActionResult Edit(UsersEditViewModel model) { // Add Data Management evaluation section changes here. // End changes. // Solution: EntityModels.AspNetUser user = db.AspNetUsers.FirstOrDefault(x => x.Id == model.Id); if (model.NewPassword != string.Empty) { user.PasswordHash = AuthController.EncodePasswordMd5(model.NewPassword); } if (model.UserRole != user.AspNetRoles.Id) { user.AspNetRoles = db.AspNetRoles.FirstOrDefault(x => x.Id == model.UserRole); } db.SaveChanges(); // End solution. return(RedirectToAction("Edit", new { id = user.Id })); }
public virtual void Remove(T item) { using (var context = new Database()) { context.Entry(ConvertToEntity(item)).State = EntityState.Deleted; context.SaveChanges(); } }
public ActionResult Register(RegisterViewModel model) { if (!ModelState.IsValid) { return(View()); } if (db.AspNetUsers.FirstOrDefault(x => x.Email == model.Email) != null) { return(View()); } if (model.Password != model.ConfirmPassword) { return(View()); } EntityModels.AspNetUser newUser = new EntityModels.AspNetUser(); newUser.Email = model.Email; newUser.FullName = model.FullName; newUser.ImgName = string.Empty; newUser.PasswordHash = EncodePasswordMd5(model.Password); newUser.AccessFailedCount = 0; newUser.AspNetRoles = db.AspNetRoles.FirstOrDefault(x => x.Name == "User"); db.AspNetUsers.Add(newUser); db.SaveChanges(); LoginViewModel loginModel = new LoginViewModel(); loginModel.Email = newUser.Email; loginModel.Password = model.Password; Login(loginModel); return(RedirectToAction("Index", "Home")); }