public ActionResult DeleteAttachment(int id)
        {
            ViewBag.MenuItem = CurrentMenuItem;

            var returnUrl = (Request.UrlReferrer ?? (object)string.Empty).ToString();

            TempData["returnUrl"] = returnUrl;

            ViewBag.ReturnUrl = returnUrl;

            var attachment = unitOfWork.Repository <Attachment>()
                             .Queryable()
                             .Include(i1 => i1.Patient)
                             .SingleOrDefault(p => p.Id == id);

            if (attachment == null)
            {
                ViewBag.Entity = "Attachment";
                return(View("NotFound"));
            }

            var model = new AttachmentDeleteModel
            {
                AttachmentId    = attachment.Id,
                Description     = attachment.Description,
                FileName        = attachment.FileName,
                PatientFullName = attachment.Patient.FullName
            };

            return(View(model));
        }
        public ActionResult DeleteAttachment(AttachmentDeleteModel model)
        {
            var returnUrl = (TempData["returnUrl"] ?? string.Empty).ToString();

            ViewBag.ReturnUrl = returnUrl;

            var attachment = unitOfWork.Repository <Attachment>()
                             .Queryable()
                             .Include(i1 => i1.Patient)
                             .SingleOrDefault(p => p.Id == model.AttachmentId);

            if (attachment != null)
            {
                var user = GetCurrentUser();

                if (user != null)
                {
                    if (ModelState.IsValid)
                    {
                        var reason = model.ArchiveReason ?? "** NO REASON SPECIFIED ** ";
                        attachment.Archived       = true;
                        attachment.ArchivedDate   = DateTime.Now;
                        attachment.ArchivedReason = reason;
                        attachment.AuditUser      = user;
                        unitOfWork.Repository <Attachment>().Update(attachment);
                        unitOfWork.Complete();

                        HttpCookie cookie = new HttpCookie("PopUpMessage");
                        cookie.Value = "Attachment record deleted successfully";
                        Response.Cookies.Add(cookie);

                        return(Redirect(returnUrl));
                    }
                }
            }

            TempData["returnUrl"] = returnUrl;

            return(View(model));
        }