public ActionResult Save(UserProfile profile) { if (FormIsValid(profile)) { if (profile.Id.Equals(0)) { UserProfile.Create(profile); } else { UserProfile.Update(profile); } AddMessage(HardCode.Constants.MessageWithSuccess); return new JsonResult { Data = Url.Action("Index") }; } return View(ResultStatus.Attention); }
private bool FormIsValid(UserProfile profile) { if (ModelState.IsValid) { if (UserProfile.Exist(profile.Id, Restrictions.Eq(Projections.SqlFunction("lower", NHibernateUtil.String, Projections.Property("Name")), profile.Name.ToLower()))) { ModelState.AddModelError("Name", "O nome informado já existe."); } return ModelState.IsValid; } return false; }