// create model for Delete view public NotificationDetailVM CreateDeleteModel(string notificationReferenceID) { var deletingNotification = _context.Notification.Where(n => n.ReferenceID == notificationReferenceID) .FirstOrDefault(); NotificationDetailVM model = new NotificationDetailVM() { ReferenceID = notificationReferenceID, NotificationDescription = deletingNotification.NotificationDescription, NotificationHeading = deletingNotification.NotificationHeading, SentDateTime = deletingNotification.SentDateTime, IncidentNumber = deletingNotification.IncidentNumber, Status = deletingNotification.Status.StatusName }; return(model); }
public ActionResult Delete(NotificationDetailVM model) { string result = ""; if (ModelState.IsValid) { bool success = _nRepo.DeleteNotification(model.ReferenceID, out result); if (success) { TempData["SuccessMsg"] = result; // handle when thread no longer exists bool emptyThread = _nRepo.CheckEmptyThread(model.IncidentNumber); if (emptyThread) { return(RedirectToAction("Index")); } return(RedirectToAction("DetailsThread", new { id = model.IncidentNumber })); } } else { TempData["ErrorMsg"] = "Cannot delete Notification, try again later."; } // recreate the model for the view model = _nRepo.CreateDeleteModel(model.ReferenceID); // if notification returns null, redirect to thread view if (model == null) { TempData["ErrorMsg"] = "Cannot delete this notification at the moment"; return(RedirectToAction("DetailsThread", new { id = model.IncidentNumber })); } TempData["ErrorMsg"] = result; return(View(model)); }