public ActionResult DeleteTest(string ID) { try { REF_TEST_TB test = _uow.Repository <REF_TEST_TB>().GetById(Convert.ToInt32(ID)); TestDeleteViewModel testDeleteViewModel = new TestDeleteViewModel() { AnalysisMethod = test.SZ_ANALYSIS_METHOD, Description = test.SZ_DESCRIPTION, EffectiveDate = test.DT_EFFECTIVE == null ? "" : test.DT_EFFECTIVE.Value.ToShortDateString(), ExpiredDate = test.DT_EXPIRED == null ? "" : test.DT_EXPIRED.Value.ToShortDateString(), SampleMedia = test.SZ_SAMPLE_MEDIA, SampleType = test.SZ_SAMPLE_TYPE, TestID = test.N_TEST_SYSID, Unit = test.SZ_TITLE, Message = "", ShowMessage = false }; return(View(testDeleteViewModel)); } catch (Exception ex) { if (ex.InnerException == null) { ViewBag.Message = "Function: TestController.DeleteTest_GET\n\nError: " + ex.Message; } else { ViewBag.Message = "Function: TestController.DeleteTest_GET\n\nError: " + (ex.Message + "\n\nInnerException: " + ex.InnerException.Message); }; Session["ErrorMessage"] = ViewBag.Message; return(RedirectToAction("InternalServerError", "Error")); }; }
public ActionResult DeleteTest(TestDeleteViewModel model) { try { int id = Convert.ToInt32(model.TestID); if (_uow.Repository <REF_TEST_X_TEST_GROUP_TB>().Find(u => u.N_TEST_SYSID == id).Count() > 0 || _uow.Repository <TRN_RESULT_TB>().Find(u => u.N_TEST_SYSID == id).Count() > 0) { model.ShowMessage = true; model.Message = "Records exist for this test. Sorry, the test can not be deleted."; return(View(model)); } else { _uow.Repository <REF_TEST_TB>().Delete(id); _uow.SaveChanges(); return(RedirectToAction("Index", new { ID = id })); } } catch (Exception ex) { if (ex.InnerException == null) { ViewBag.Message = "Function: TestController.DeleteTest_POST\n\nError: " + ex.Message; } else { ViewBag.Message = "Function: TestController.DeleteTest_POST\n\nError: " + (ex.Message + "\n\nInnerException: " + ex.InnerException.Message); }; Session["ErrorMessage"] = ViewBag.Message; return(RedirectToAction("InternalServerError", "Error")); }; }
public async Task <ActionResult> Delete(TestDeleteViewModel model) { if (ModelState.IsValid) { var test = await db.Tests.FindAsync(model.Id); if (test == null) { return(View("Error")); } test.IsVisible = false; await db.SaveChangesAsync(); return(RedirectToAction("View", "Course", new { id = model.CourseId })); } return(View(model)); }