public ActionResult Add(UserModel userModel) { try { UserRepository.Add(new User() { UserName = userModel.UserName, Password = userModel.Password, Email = userModel.Email, SecurityQuestion = userModel.SecurityQuestion, SecurityAnswer = userModel.SecurityAnswer, Roles = userModel.Roles }); return RedirectToAction("Index"); } catch(Exception ex) { ModelState.AddModelError("", ex.Message); ViewBag.Roles = RoleRepository.GetRoles(); return View(userModel); } }
public ActionResult Edit(string userName) { ViewBag.Roles = RoleRepository.GetRoles(); User user = UserRepository.GetUser(userName); UserModel userModel = new UserModel() { UserName = user.UserName, Email = user.Email, SecurityQuestion = user.SecurityQuestion, SecurityAnswer = user.SecurityAnswer, Roles = user.Roles }; return View(userModel); }