public JsonResult JsonCreateRequest(PassRequestHed passReq) { int Ref = 0; try { Ref = PassRequestFacade.SavePassRequest(passReq); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } return(Json(new { refNo = Ref })); }
public ActionResult Find(string NIC) { try { int Req = PassRequestFacade.GetRequestFromID(NIC); if (Req == 0) { ModelState.AddModelError("ErrorMsg", "No Records Found"); return(View()); } return(RedirectToAction("View", new { ReqNo = Req, ID = NIC })); } catch (Exception ex) { ModelState.AddModelError("ErrorMsg", "Error: " + ex.ToString()); return(RedirectToAction("Find")); } }