public ActionResult Reason(int id) { SlippingRequest slippingRequest = Get(id); if (slippingRequest != null && !IsSubmitted(slippingRequest)) { var model = new ReasonAndDetails { Reasons = ReasonRepository.Get().Where(r => r.ID != 4).ToList(), ID = slippingRequest.ID, Reason = slippingRequest.ReasonID.HasValue ? slippingRequest.ReasonID.ToString() : "-1" }; switch (model.Reason) { case "1": model.Details1 = slippingRequest.Details ?? string.Empty; break; case "2": model.Details2 = slippingRequest.Details ?? string.Empty; break; case "3": model.Details3 = slippingRequest.Details ?? string.Empty; break; case "5": model.Details4 = slippingRequest.Details ?? string.Empty; break; } return(View(model)); } else { return(RedirectToAction("NotFound")); } }
public ActionResult Reason(int id, ReasonAndDetails model) { SlippingRequest slippingRequest = Get(id); //mapping correct reason details switch (model.Reason) { case "1": if (string.IsNullOrWhiteSpace(model.Details1)) { ModelState.AddModelError("Details1", "A description of the reason is required"); } break; case "2": if (string.IsNullOrWhiteSpace(model.Details2)) { ModelState.AddModelError("Details2", "A description of the reason is required"); } break; case "3": if (string.IsNullOrWhiteSpace(model.Details3)) { ModelState.AddModelError("Details3", "A description of the reason is required"); } break; case "5": if (string.IsNullOrWhiteSpace(model.Details4)) { ModelState.AddModelError("Details4", "A description of the reason is required"); } break; } if (slippingRequest != null && !IsSubmitted(slippingRequest)) { if (ModelState.IsValid) { slippingRequest.ReasonID = Convert.ToInt32(model.Reason); switch (model.Reason) { case "1": slippingRequest.Details = model.Details1; break; case "2": slippingRequest.Details = model.Details2; break; case "3": slippingRequest.Details = model.Details3; break; case "5": slippingRequest.Details = model.Details4; break; } CreateOrUpdate(slippingRequest); return(RedirectToAction("OppositionMPs")); } else { model.Reasons = ReasonRepository.Get().Where(r => r.ID != 4).ToList(); return(View(model)); } } else { return(RedirectToAction("NotFound")); } }