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); // reconcile the recharge codes UpdateRechargeAccounts(userToEdit.RechargeAccounts, user.RechargeAccounts); ModelState.Clear(); userToEdit.TransferValidationMessagesTo(ModelState); if (ModelState.IsValid) { _repositoryFactory.UserRepository.EnsurePersistent(userToEdit); Message = "User has been updated"; return(RedirectToAction("Users")); } var viewModel = UserViewModel.CreateForUser(_repositoryFactory, CurrentUser.Identity.Name, user); return(View(viewModel)); }
public ActionResult CreateUser(User user, string password, string retypePassword) { user.ParentUser = GetCurrentUser(true); if (password != retypePassword) { ModelState.AddModelError("Password", "Passwords do not match."); } if (ModelState.IsValid) { if (!WebSecurity.UserExists(user.UserName)) { // create the user WebSecurity.CreateUserAndAccount(user.UserName, password, new { FirstName = user.FirstName, LastName = user.LastName, Title = user.Title, Phone = user.Phone, fax = user.Fax, parentUserId = user.ParentUser.Id }); } Roles.AddUserToRole(user.UserName, RoleNames.User); Message = "User has been created."; return(RedirectToAction("Users")); } var viewModel = UserViewModel.CreateForUser(_repositoryFactory, CurrentUser.Identity.Name, 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.CreateForUser(_repositoryFactory, CurrentUser.Identity.Name, user); return(View(viewModel)); }
public ActionResult CreateUser() { var viewModel = UserViewModel.CreateForUser(_repositoryFactory, CurrentUser.Identity.Name); return(View(viewModel)); }