public ActionResult EditUser(int id, User user, string password, string retypePassword) { var userToEdit = _repositoryFactory.UserRepository.GetNullableById(id); if (userToEdit == null) { Message = "User was not found"; return(RedirectToAction("Users")); } // copy the main fields AutoMapper.Mapper.Map(user, userToEdit); ModelState.Clear(); userToEdit.TransferValidationMessagesTo(ModelState); if (ModelState.IsValid) { _repositoryFactory.UserRepository.EnsurePersistent(userToEdit); Message = "User has been updated"; return(RedirectToAction("Users")); } var viewModel = UserViewModel.CreateForPi(_repositoryFactory, user); return(View(viewModel)); }
public ActionResult EditUser(int id) { var user = _repositoryFactory.UserRepository.GetNullableById(id); if (user == null) { Message = "User was not found"; return(RedirectToAction("Users")); } var viewModel = UserViewModel.CreateForPi(_repositoryFactory, user); return(View(viewModel)); }
public ActionResult CreateUser(User user, string password, string retypePassword, List <string> roles) { if (user.University == null) { ModelState.AddModelError("Univerrsity", "University is required"); } if (user.Department == null) { ModelState.AddModelError("Department", "Department is Required"); } if (roles == null || !roles.Any()) { ModelState.AddModelError("Roles", "At least one role is required"); } if (password != retypePassword) { ModelState.AddModelError("Password", "Passwords do not match."); } if (ModelState.IsValid) { if (!WebSecurity.UserExists(user.UserName)) { WebSecurity.CreateUserAndAccount(user.UserName, password, new { FirstName = user.FirstName, LastName = user.LastName, Title = user.Title, Phone = user.Phone, fax = user.Fax, UniversityId = user.University.Id, DepartmentId = user.Department.Id }); } foreach (var role in roles) { Roles.AddUserToRole(user.UserName, role); } Message = "User has been created."; return(RedirectToAction("Users")); } var viewModel = UserViewModel.CreateForPi(_repositoryFactory, user); return(View(viewModel)); }
public ActionResult CreateUser() { var viewModel = UserViewModel.CreateForPi(_repositoryFactory); return(View(viewModel)); }