//[Bind(Include = "User.Name,User.Username,User.Password,ConfirmPassword,User.EmailAdress,User.IsActive")] public ActionResult Create(VMUserCreate model) { if (model.User.Password != model.ConfirmPassword) { ModelState.AddModelError("User.Password", "The passwords don't match"); ModelState.AddModelError("ConfirmPassword", "The password don't match"); model.ConfirmPassword = model.User.Password = String.Empty; } if(UOW.UserRepository.Get(c => c.Name == model.User.Name).ToList().Count() > 0) { TempData["Alert"] = AlertHelper.GenerateAlert(Models.Widgets.NotificationType.ERROR, "Already exists one user with this name."); return View(model); } if (UOW.UserRepository.Get(c => c.Username == model.User.Username).ToList().Count() > 0) { TempData["Alert"] = AlertHelper.GenerateAlert(Models.Widgets.NotificationType.ERROR, "Already exists one user with this username."); return View(model); } if (UOW.UserRepository.Get(c => c.EmailAdress == model.User.EmailAdress).ToList().Count() > 0) { TempData["Alert"] = AlertHelper.GenerateAlert(Models.Widgets.NotificationType.ERROR, "Already exists one user with this email address."); return View(model); } if (ModelState.IsValid) { model.User.Password = BCrypt.HashPassword(model.User.Password, BCrypt.GenerateSalt()); model.User.CreatedBy = UOW.UserRepository.Get().First().Id; model.User.CreatedAt = DateTime.Now; UOW.UserRepository.Insert(model.User); UOW.Save(); TempData["Alert"] = AlertHelper.GenerateAlert(Models.Widgets.NotificationType.SUCCESS, "User inserted successfully."); return RedirectToAction("Index"); } return View(model); }
// GET: User/Create public ActionResult Create() { VMUserCreate model = new VMUserCreate(); return View(model); }