public ActionResult Create(UserModel userModel) { if (userModel.Password.IsNullOrEmpty()) ModelState.AddModelError("Password", "Please fill in a password."); if (!ModelState.IsValid) return View(userModel); var user = new User(); user.Username = userModel.User.Username; if (!userModel.Password.IsNullOrEmpty()) user.PasswordHashed = Hash.Make(userModel.Password); user.DateCreated = DateTime.Now; user.Role = userModel.User.Role; user.Email = userModel.User.Email; user.Website = FixWebsiteUrl(userModel.User.Website); user.TwitterUsername = FixTwitterUsername(userModel.User.TwitterUsername); _userService.Create(user); _userService.Save(); return RedirectToAction("Index"); }
public ActionResult Edit(int id) { var user = _userService.GetById(id); if (user == null) return View("NotFound", new NotFoundModel()); var model = new UserModel(user); return View(model); }
public ActionResult Edit(int id, UserModel userModel) { if (!ModelState.IsValid) return View(userModel); var user = _userService.GetById(id); user.Username = userModel.User.Username; if (!userModel.Password.IsNullOrEmpty()) user.PasswordHashed = Hash.Make(userModel.Password); user.Role = userModel.User.Role; user.Email = userModel.User.Email; user.Website = FixWebsiteUrl(userModel.User.Website); user.TwitterUsername = FixTwitterUsername(userModel.User.TwitterUsername); _userService.Save(); return RedirectToAction("Index"); }