Ejemplo n.º 1
0
 public bool CancelSlip(int userId, SlipSummary slip)
 {
     if (UserCanActForMP(userId, slip.MPID))
     {
         var ar = db.AbsenceRequests.Find(slip.ID);
         ar.StatusID = 7; // Cancelled
         try
         {
             db.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
     else
     {
         throw new Exception("Unauthorised");
     }
 }
        public ActionResult Review(int id, SlipSummary model)
        {
            var slip = SlippingRepository.GetSummaries(MPID, SlippingUser.ID).FirstOrDefault(s => s.ID == id);

            if (slip != null && slip.Status != "Refused" && slip.Status != "Revoked" && slip.Status != "Cancelled")
            {
                string displayDate = GetDateForEmail(slip.FromDate, slip.ToDate);

                if (CancelSlip(slip, SlippingUser.ID))
                {
                    Dictionary <string, dynamic> parameters = new Dictionary <string, dynamic>()
                    {
                        { "absence_date", displayDate },
                        { "name", string.Format("{0} {1}", SlippingUser.Forenames, SlippingUser.Surname) },
                        { "reference", slip.ID }
                    };

                    if (!string.IsNullOrEmpty(NotifyTemplateId_SlippingRequestCancelledUser))
                    {
                        if (!SlippingUser.IsMP)
                        {
                            SendNotification(NotifyTemplateId_SlippingRequestCancelledUser, SlippingUser.EmailAddress, new Dictionary <string, dynamic>()
                            {
                                { "absence_date", displayDate },
                                { "name", string.Format("{0} {1}", SlippingUser.Forenames, SlippingUser.Surname) },
                                { "reference", slip.ID }
                            });
                        }

                        MP mp = this.MPRepository.Get(slip.MPID, SlippingUser.ID);

                        if (mp != null)
                        {
                            SendNotification(NotifyTemplateId_SlippingRequestCancelledUser, GetMPEmailAddress(slip.MPID, SlippingUser.ID), new Dictionary <string, dynamic>()
                            {
                                { "absence_date", displayDate },
                                { "name", mp.Name },
                                { "reference", slip.ID }
                            });
                        }
                        else
                        {
                            throw new Exception(string.Format("Cannot find MP for Slip {0}.", slip.ID));
                        }
                    }
                    else
                    {
                        throw new Exception("NotifyTemplateId_SlippingRequestCancelledUser in web.config missing or invalid");
                    }

                    if (!string.IsNullOrEmpty(NotifyTemplateId_SlippingRequestCancelledAdmin) && !string.IsNullOrEmpty(SlippingRequestReviewersEmailAddress))
                    {
                        SendNotification(NotifyTemplateId_SlippingRequestCancelledAdmin, SlippingRequestReviewersEmailAddress, new Dictionary <string, dynamic>()
                        {
                            { "absence_date", displayDate },
                            { "name", string.Format("{0} {1}", SlippingUser.Forenames, SlippingUser.Surname) },
                            { "reference", slip.ID }
                        });
                    }
                    else
                    {
                        throw new Exception("NotifyTemplateId_SlippingRequestCancelledAdmin and/or SlippingRequestReviewersEmailAddress in web.config missing or invalid");
                    }
                    return(RedirectToAction("Cancelled"));
                }
                else
                {
                    ModelState.AddModelError("ID", "Error cancelling slip. Please try again later or contact the Whips Office.");
                    return(View(slip));
                }
            }
            else
            {
                return(RedirectToAction("NotFound", "Home"));
            }
        }
 private bool CancelSlip(SlipSummary slip, int userId)
 {
     return(SlippingRepository.CancelSlip(userId, slip));
 }