public ActionResult DeleteUserById(int?id) { if (id.HasValue) { MembershipUser editUser = _membershipService.GetUser(id.Value); MembershipUpdateViewModel userEditVM = new MembershipUpdateViewModel { Id = editUser.Id, IsApproved = editUser.IsApproved, Email = editUser.Email, UserName = editUser.UserName }; return(View(userEditVM)); } return(View()); }
public ActionResult EditUser(int?id, MembershipUpdateViewModel userEdit) { if (id.HasValue) { MembershipUser updateUser = _membershipService.GetUser(userEdit.Id.Value); updateUser.IsApproved = userEdit.IsApproved; if (updateUser.UserName != userEdit.UserName) { if (_membershipService.GetUserByName(userEdit.UserName) != null) { ModelState.AddModelError(string.Empty, "Username already exists."); return(View(userEdit)); } else { updateUser.UserName = userEdit.UserName; } } if (updateUser.Email != userEdit.Email) { if (_membershipService.GetUserByEmail(userEdit.Email) != null) { ModelState.AddModelError(string.Empty, "Email already exists."); return(View(userEdit)); } else { updateUser.Email = userEdit.Email; } } UnitOfWork.SaveChanges(); TempData["Success"] = "User updated successfully!"; } return(RedirectToAction("Index")); }