public ActionResult DeleteSample(SampleTblDeleteViewModel model) { try { int id = Convert.ToInt32(model.ID); if (_uow.Repository <TRN_RESULT_TB>().Find(u => u.N_SAMPLE_SYSID == id).Count() > 0) { model.ShowMessage = true; model.Message = "Result records exist for this Sample. Sorry, the Sample can not be deleted."; return(View("Delete", model)); } else { _uow.Repository <TRN_SAMPLE_TB>().Delete(id); _uow.SaveChanges(); return(RedirectToAction("Index", new { ID = id })); } } catch (Exception ex) { if (ex.InnerException == null) { ViewBag.Message = "Function: SampleTblController.Delete_POST\n\nError: " + ex.Message; } else { ViewBag.Message = "Function: SampleTblController.Delete_POST\n\nError: " + (ex.Message + "\n\nInnerException: " + ex.InnerException.Message); }; Session["ErrorMessage"] = ViewBag.Message; return(RedirectToAction("InternalServerError", "Error")); }; }
public ActionResult Delete(SampleTblDeleteViewModel model) { try { TRN_SAMPLE_TB sample = _uow.Repository <TRN_SAMPLE_TB>().GetById(model.ID); SampleTblDeleteViewModel sampleTblDeleteViewModel = new SampleTblDeleteViewModel() { ID = sample.N_SAMPLE_SYSID, Message = "", ShowMessage = false }; return(View("Delete", sampleTblDeleteViewModel)); } catch (Exception ex) { if (ex.InnerException == null) { ViewBag.Message = "Function: SampleTblController.Delete_GET\n\nError: " + ex.Message; } else { ViewBag.Message = "Function: SampleTblController.Delete_GET\n\nError: " + (ex.Message + "\n\nInnerException: " + ex.InnerException.Message); }; Session["ErrorMessage"] = ViewBag.Message; return(RedirectToAction("InternalServerError", "Error")); }; }