public ActionResult DeleteAppointment(int id) { ViewBag.MenuItem = CurrentMenuItem; var returnUrl = (Request.UrlReferrer ?? (object)string.Empty).ToString(); TempData["returnUrl"] = returnUrl; ViewBag.ReturnUrl = returnUrl; var appointment = unitOfWork.Repository <Appointment>() .Queryable() .Include(i1 => i1.Patient) .SingleOrDefault(p => p.Id == id); if (appointment == null) { ViewBag.Entity = "Appointment"; return(View("NotFound")); } var model = new AppointmentDeleteModel { AppointmentId = appointment.Id, AppointmentDate = appointment.AppointmentDate, PatientFullName = appointment.Patient.FullName }; return(View(model)); }
public ActionResult DeleteAppointment(AppointmentDeleteModel model) { var returnUrl = (TempData["returnUrl"] ?? string.Empty).ToString(); ViewBag.ReturnUrl = returnUrl; var appointment = unitOfWork.Repository <Appointment>() .Queryable() .Include(i1 => i1.Patient) .SingleOrDefault(p => p.Id == model.AppointmentId); if (appointment != null) { var user = GetCurrentUser(); if (user != null) { if (ModelState.IsValid) { var reason = model.ArchiveReason ?? "** NO REASON SPECIFIED ** "; appointment.Archived = true; appointment.ArchivedDate = DateTime.Now; appointment.ArchivedReason = reason; appointment.AuditUser = user; unitOfWork.Repository <Appointment>().Update(appointment); unitOfWork.Complete(); HttpCookie cookie = new HttpCookie("PopUpMessage"); cookie.Value = "Appointment record deleted successfully"; Response.Cookies.Add(cookie); return(Redirect(returnUrl)); } } } TempData["returnUrl"] = returnUrl; return(View(model)); }