public ActionResult DeleteStatus(string status, DeleteStatusViewModel model) { try { Status s = statusRepo.FindStatus(status); Status snew = statusRepo.FindStatus(model.SelectedStatusId); hotelRepo.FindAll().Where(t => t.Status.St == s.St).ToList().ForEach(t => { t.Status = snew; }); statusRepo.RemoveStatus(s); statusRepo.SaveChanges(); TempData["message"] = "The status has succesfully been deleted"; }catch (Exception ex) { TempData["error"] = "There was a problem deleting the status. Please contact the IT department."; } return(RedirectToAction("Index")); }
public ActionResult DeleteStatus(string status) { Status s = statusRepo.FindStatus(status); if (s == null) { TempData["error"] = "Something whent wrong. Please contact the IT department."; return(RedirectToAction("Index")); } int count = hotelRepo.FindAll().Where(t => t.Status.St == s.St).Count(); DeleteStatusViewModel dsvm = new DeleteStatusViewModel(s, count) { SelectedStatusId = statusRepo.FindAll().Where(t => t.St != s.St).OrderBy(t => t.St).FirstOrDefault().St, Statusses = statusRepo.FindAll().Where(t => t.St != s.St).OrderBy(t => t.St).Select(t => new SelectListItem { Text = t.St, Value = t.St }) }; return(View(dsvm)); }