public ActionResult Save(facility_contract facility_contract) { try { if (ModelState.IsValid) { if (facility_contract.fct_start_date.HasValue && facility_contract.fct_end_date.HasValue) { if (facility_contract.fct_start_date > facility_contract.fct_end_date) { ModelState.AddModelError("fct_start_date", "Start Date can not be greater then End Date"); } } if (ModelState.IsValid) // re validating the model after custom validations { if (_facilityContractService.Exists(facility_contract.fct_key)) { facility_contract.fct_modified_by = User.Identity.GetUserId(); facility_contract.fct_modified_date = DateTime.Now.ToEST(); _facilityContractService.Edit(facility_contract); SaveSelectedServices(facility_contract, true); } else { facility_contract.fct_created_by = User.Identity.GetUserId(); facility_contract.fct_created_date = DateTime.Now.ToEST(); _facilityContractService.Create(facility_contract); SaveSelectedServices(facility_contract, false); } return(Json(new { success = true })); } } return(Json(new { success = false, data = string.Join("<br/>", this.GetModalErrors().Values) })); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); return(Json(new { success = false, data = "An error occurred while processing your request, please try later." })); } }