public static void SendReminders(this ICanAction approvalFlow) { var application = approvalFlow.GetMetadata("app"); var empProvider = EmployeeProvider.GetEmployeeProvider(); var portalPath = ConfigurationManager.AppSettings["PortalPath"]; var obj = (IApprovalFlow <ITransition>)approvalFlow; var path = approvalFlow.GetMetadata("path"); string longDescription = approvalFlow.GetMetadata("longDescription"); string shortDescription = approvalFlow.GetMetadata("shortDescription"); string objID = approvalFlow.GetMetadata("id"); var transitionsAwaitingDecision = obj.Transitions.Where(t => t.ApproverDecision == DecisionType.AwaitingDecision && t.RequestedDate < DateTime.Now.AddDays(-2)).OrderByDescending(t => t.Order).ToList(); foreach (var transition in transitionsAwaitingDecision) { Employee u1 = empProvider.GetUserData(transition.ApproverID); Employee u2 = empProvider.GetUserData(transition.RequesterID); string msg = "Your Action is Required. Requested by " + u2.DisplayName + "."; if (transition.RequesterComments != null) { msg = msg + "<br/><br/><p>Comments : <br/>" + transition.RequesterComments + "</p>"; } var mail = new EmailMessage() { Sender = "*****@*****.**", RecipientName = u1.DisplayName, Recipient = u1.Mail, CCRecipients = new string[] { u2.Mail }, Subject = "(" + application + ") " + shortDescription + ", Reminder Notification: " + transition.ApproverDecision.GetDisplay(), Body = msg + "<br/><a href=\"" + portalPath + path + "/Index/" + obj.GetID() + "\"/>Open Document</a><br/><br/>" }; if (!(transition.ApproverID == "52980409" && path == "/Procurement/Requisitions")) { using (var email = new EmailHandler(mail)) email.Send(); RegisterAlert.ForApp(application) .WithCategory("Approval Reminder") .ByUser(transition.RequesterID) .ToTargetEmployees(new string[] { transition.ApproverID }) .IsMajor() .WithMessage(shortDescription + ", Approval Notification: " + transition.ApproverDecision.GetDisplay() + ". Requested by " + u2.DisplayName + ".") .WithURL(portalPath + path + "/Index/" + objID) .PushAlert(); } } }
public static void FireNotifications(this ICanAction approvalFlow) { var notifications = approvalFlow.GetPAFNotifications() ?? new List <PAFNotification>(); var empProvider = EmployeeProvider.GetEmployeeProvider(); var portalPath = ConfigurationManager.AppSettings["PortalPath"]; approvalFlow.SetEntityMetaData(); var path = approvalFlow.GetMetadata("path"); var application = approvalFlow.GetMetadata("app"); string longDescription = approvalFlow.GetMetadata("longDescription"); string shortDescription = approvalFlow.GetMetadata("shortDescription"); string objID = approvalFlow.GetMetadata("id"); List <EmailMessage> mailList = new List <EmailMessage>(); List <string> CCs = new List <string>(); if (notifications != null) { if (notifications.Any()) { foreach (var item in notifications) { var sender = item.From == null ? null : empProvider.GetUserData(item.From); var recipient = empProvider.GetUserData(item.To); if (sender != null) { CCs.Add(sender.Mail); } if (item.UsersToCC != null) { CCs.AddRange(item.UsersToCC.Select(e => empProvider.GetUserData(e).Mail).Distinct().ToList()); } string msg; string alertMessage = ""; string decisionDisplay = item.DecisionType.GetDisplay(); switch (item.DecisionType) { case DecisionType.AwaitingDecision: msg = "Your Action is Required."; if (sender != null) { msg = msg + " Requested by " + sender.DisplayName + "."; alertMessage = ". Requested by " + sender.DisplayName + "."; } if (item.Comments != null) { msg = msg + "<br/>" + longDescription + "<br/><br/><p>Comments : <br/>" + item.Comments + "</p>"; } break; case DecisionType.Approved: msg = "Document Approved"; if (sender != null) { msg = msg + " by " + sender.DisplayName; alertMessage = ", By " + sender.DisplayName + "."; } msg += "."; if (item.Comments != null) { msg = msg + "<br/>" + longDescription + "<br/><br/><p>Comments : <br/>" + item.Comments + "</p>"; } break; case DecisionType.Rejected: msg = "Document Rejected"; if (sender != null) { msg = msg + " by " + sender.DisplayName; alertMessage = ", By " + sender.DisplayName + "."; } msg += "."; if (item.Comments != null) { msg = msg + "<br/>" + longDescription + "<br/><br/><p>Comments : <br/>" + item.Comments + "</p>"; } break; case DecisionType.Invalidated: msg = "Your request to review is invalidated."; alertMessage = ""; if (item.Comments != null) { msg = msg + "<br/>" + longDescription + "<br/><br/><p>Comments : <br/>" + item.Comments + "</p>"; } break; default: msg = ""; break; } var mail = new EmailMessage() { Sender = "*****@*****.**", RecipientName = recipient.DisplayName, Recipient = recipient.Mail, CCRecipients = CCs.ToArray(), Subject = $"[{application}] {shortDescription}, Approval Notification: {decisionDisplay}", Body = msg + "<br/><a href=\"" + portalPath + path + "/Index/" + objID + "\"/>Open Document</a><br/><br/>" }; mailList.Add(mail); if (sender != null) { alertMessage = shortDescription + " Approval Notification: " + decisionDisplay + alertMessage; var alert = RegisterAlert.ForApp(application) .WithCategory("Approval") .ByUser(sender.Username) .ToTargetEmployees(new string[] { recipient.Username }); if (item.DecisionType == DecisionType.AwaitingDecision) { alert = alert.IsMajor(); } else { alert = alert.IsInformation(); } alert.WithMessage(alertMessage) .WithURL(portalPath + path + "/Index/" + objID) .PushAlert(); } } //using (var email = new EmailHandler(mailList)) // email.Send(); approvalFlow.ClearNotifications(); } } }