public ActionResult Save(User user) { ExcludePropertiesInValidation("Profile.Name", "Profile.Functionalities"); if (FormIsValid(user)) { user.Password = Models.User.EncriptPassword(user.Password); if (user.Id.Equals(0)) { Models.User.Create(user); } else { Models.User.Update(user); } AddMessage(HardCode.Constants.MessageWithSuccess); return new JsonResult { Data = Url.Action("Index", "Users") }; } return View(ResultStatus.Attention); }
private bool FormIsValid(User user) { if (ModelState.IsValid) { if (Models.User.Exist(user.Id, Restrictions.Eq(Projections.SqlFunction("lower", NHibernateUtil.String, Projections.Property("Login")), user.Login.ToLower()))) { ModelState.AddModelError("Login", "O login informado já existe."); } if (!string.IsNullOrEmpty(user.Email) && Models.User.Exist(user.Id, Restrictions.Eq(Projections.SqlFunction("lower", NHibernateUtil.String, Projections.Property("Email")), user.Login.ToLower()))) { ModelState.AddModelError("Login", "O e-mail informado já existe."); } return ModelState.IsValid; } return false; }