public static void SendSubmittedMessage(List <Person> peopleToNotify, ProjectUpdateBatch projectUpdateBatch)
        {
            Check.Require(projectUpdateBatch.ProjectUpdateState == ProjectUpdateState.Submitted, "Need to be in Submitted state to send the Submitted email!");
            var latestProjectUpdateHistorySubmitted = projectUpdateBatch.GetLatestProjectUpdateHistorySubmitted();
            var submitterPerson = latestProjectUpdateHistorySubmitted.UpdatePerson;
            var submitterEmails = new List <string> {
                submitterPerson.Email
            };
            var primaryContactPerson = projectUpdateBatch.Project.GetPrimaryContact();

            if (primaryContactPerson != null && !string.Equals(primaryContactPerson.Email, submitterPerson.Email, StringComparison.InvariantCultureIgnoreCase))
            {
                submitterEmails.Add(primaryContactPerson.Email);
            }
            var contactsWhoCanManageProject = projectUpdateBatch.Project.GetContactsWhoCanManageProject();

            foreach (var contact in contactsWhoCanManageProject)
            {
                if (!string.Equals(contact.Email, submitterPerson.Email, StringComparison.InvariantCultureIgnoreCase) && (primaryContactPerson == null || !string.Equals(contact.Email, primaryContactPerson.Email, StringComparison.InvariantCultureIgnoreCase)))
                {
                    submitterEmails.Add(contact.Email);
                }
            }

            var emailsToSendTo  = peopleToNotify.Select(x => x.Email).ToList();
            var subject         = $"The update for {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} {projectUpdateBatch.Project.GetDisplayName()} was submitted";
            var instructionsUrl = SitkaRoute <ProjectUpdateController> .BuildAbsoluteUrlHttpsFromExpression(x => x.Instructions(projectUpdateBatch.Project));

            var message = $@"
<p>The update for {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} {projectUpdateBatch.Project.GetDisplayName()} on {
                    latestProjectUpdateHistorySubmitted.TransitionDate.ToStringDate()
                } was just submitted by {submitterPerson.GetFullNameFirstLastAndOrg()}.</p>
<p>Please review and Approve or Return it at your earliest convenience.<br />
<a href=""{instructionsUrl}"">View this {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} update</a></p>
{$"- {MultiTenantHelpers.GetToolDisplayName()} team"}<br/><br/><img src=""cid:tool-logo"" width=""160"" />
<p>You received this email because you are assigned to receive support notifications within the ProjectFirma tool.</p>
";

            var mailMessage = new MailMessage {
                Subject = subject, Body = message, IsBodyHtml = true
            };

            var tenantAttribute = MultiTenantHelpers.GetTenantAttributeFromCache();
            var toolLogo        = tenantAttribute.TenantSquareLogoFileResourceInfo ??
                                  tenantAttribute.TenantBannerLogoFileResourceInfo;
            var htmlView = AlternateView.CreateAlternateViewFromString(message, null, "text/html");

            htmlView.LinkedResources.Add(
                new LinkedResource(new MemoryStream(toolLogo.FileResourceData.Data), "img/jpeg")
            {
                ContentId = "tool-logo"
            });
            mailMessage.AlternateViews.Add(htmlView);

            SendMessageAndLogNotificationForProjectUpdateTransition(projectUpdateBatch, mailMessage, emailsToSendTo, submitterEmails, new List <string>(), NotificationType.ProjectUpdateSubmitted);
        }
        public static void SendSubmittedMessage(List <Person> peopleToNotify, ProjectUpdateBatch projectUpdateBatch)
        {
            Check.Require(projectUpdateBatch.ProjectUpdateState == ProjectUpdateState.Submitted, "Need to be in Submitted state to send the Submitted email!");
            var latestProjectUpdateHistorySubmitted = projectUpdateBatch.GetLatestProjectUpdateHistorySubmitted();
            var submitterPerson = latestProjectUpdateHistorySubmitted.UpdatePerson;
            var submitterEmails = new List <string> {
                submitterPerson.Email
            };
            var primaryContactPerson = projectUpdateBatch.Project.GetPrimaryContact();

            if (primaryContactPerson != null && !string.Equals(primaryContactPerson.Email, submitterPerson.Email, StringComparison.InvariantCultureIgnoreCase))
            {
                submitterEmails.Add(primaryContactPerson.Email);
            }
            var contactsWhoCanManageProject = projectUpdateBatch.Project.GetContactsWhoCanManageProject();

            foreach (var contact in contactsWhoCanManageProject)
            {
                if (!string.Equals(contact.Email, submitterPerson.Email, StringComparison.InvariantCultureIgnoreCase) && (primaryContactPerson == null || !string.Equals(contact.Email, primaryContactPerson.Email, StringComparison.InvariantCultureIgnoreCase)))
                {
                    submitterEmails.Add(contact.Email);
                }
            }

            var emailsToSendTo  = peopleToNotify.Select(x => x.Email).ToList();
            var subject         = $"The update for {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} {projectUpdateBatch.Project.GetDisplayName()} was submitted";
            var instructionsUrl = SitkaRoute <ProjectUpdateController> .BuildAbsoluteUrlHttpsFromExpression(x => x.Instructions(projectUpdateBatch.Project));

            var message = $@"
<p>The update for {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} {projectUpdateBatch.Project.GetDisplayName()} on {
                    latestProjectUpdateHistorySubmitted.TransitionDate.ToStringDate()
                } was just submitted by {submitterPerson.GetFullNameFirstLastAndOrg()}.</p>
<p>Please review and Approve or Return it at your earliest convenience.<br />
<a href=""{instructionsUrl}"">View this {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} update</a></p>
<p>You received this email because you are assigned to receive support notifications within the ProjectFirma tool.</p>
";

            var mailMessage = new MailMessage {
                Subject = subject, Body = message, IsBodyHtml = true
            };

            SendMessageAndLogNotificationForProjectUpdateTransition(projectUpdateBatch, mailMessage, emailsToSendTo, submitterEmails, new List <string>(), NotificationType.ProjectUpdateSubmitted);
        }
        private static void SendMessageAndLogNotificationForProjectUpdateTransition(ProjectUpdateBatch projectUpdateBatch,
                                                                                    MailMessage mailMessage,
                                                                                    List <string> emailsToSendTo,
                                                                                    List <string> emailsToReplyTo,
                                                                                    List <string> emailsToCc, NotificationType notificationType)
        {
            var latestProjectUpdateHistorySubmitted = projectUpdateBatch.GetLatestProjectUpdateHistorySubmitted();
            var submitterPerson      = latestProjectUpdateHistorySubmitted.UpdatePerson;
            var primaryContactPerson = projectUpdateBatch.Project.GetPrimaryContact();

            var notificationPeople = new List <Person> {
                submitterPerson
            };

            if (primaryContactPerson != null && submitterPerson.PersonID != primaryContactPerson.PersonID)
            {
                notificationPeople.Add(primaryContactPerson);
            }

            var contactsWhoCanManageProject = projectUpdateBatch.Project.GetContactsWhoCanManageProject();

            foreach (var contact in contactsWhoCanManageProject)
            {
                if (contact.PersonID != submitterPerson.PersonID && (primaryContactPerson == null || primaryContactPerson.PersonID != contact.PersonID))
                {
                    notificationPeople.Add(contact);
                }
            }

            NotificationModelExtensions.SendMessageAndLogNotification(mailMessage,
                                                                      emailsToSendTo,
                                                                      emailsToReplyTo,
                                                                      emailsToCc,
                                                                      notificationPeople,
                                                                      DateTime.Now,
                                                                      new List <Project> {
                projectUpdateBatch.Project
            },
                                                                      notificationType,
                                                                      MultiTenantHelpers.GetToolDisplayName());
        }
        public static void SendReturnedMessage(List <Person> peopleToCc, ProjectUpdateBatch projectUpdateBatch)
        {
            Check.Require(projectUpdateBatch.ProjectUpdateState == ProjectUpdateState.Returned, "Need to be in Returned state to send the Returned email!");
            var latestProjectUpdateHistorySubmitted = projectUpdateBatch.GetLatestProjectUpdateHistorySubmitted();
            var submitterPerson = latestProjectUpdateHistorySubmitted.UpdatePerson;
            var emailsToSendTo  = new List <string> {
                submitterPerson.Email
            };

            var personNames          = submitterPerson.GetFullNameFirstLast();
            var primaryContactPerson = projectUpdateBatch.Project.GetPrimaryContact();

            if (primaryContactPerson != null && !String.Equals(primaryContactPerson.Email, submitterPerson.Email, StringComparison.InvariantCultureIgnoreCase))
            {
                emailsToSendTo.Add(primaryContactPerson.Email);
                personNames += $" and {primaryContactPerson.GetFullNameFirstLast()}";
            }
            var contactsWhoCanManageProject = projectUpdateBatch.Project.GetContactsWhoCanManageProject();

            foreach (var contact in contactsWhoCanManageProject)
            {
                if (!string.Equals(contact.Email, submitterPerson.Email, StringComparison.InvariantCultureIgnoreCase) && (primaryContactPerson == null || !string.Equals(contact.Email, primaryContactPerson.Email, StringComparison.InvariantCultureIgnoreCase)))
                {
                    emailsToSendTo.Add(contact.Email);
                    personNames += $" and {contact.GetFullNameFirstLast()}";
                }
            }

            var returnerPerson  = projectUpdateBatch.GetLatestProjectUpdateHistoryReturned().UpdatePerson;
            var instructionsUrl = SitkaRoute <ProjectUpdateController> .BuildAbsoluteUrlHttpsFromExpression(x => x.Instructions(projectUpdateBatch.Project));

            var message = $@"
Dear {personNames},
<p>
    The update submitted for {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} {
                    projectUpdateBatch.Project.GetDisplayName()
                } on {latestProjectUpdateHistorySubmitted.TransitionDate.ToStringDate()} has been returned by {
                    returnerPerson.GetFullNameFirstLastAndOrg()
                }.
</p>
<p>
    <a href=""{instructionsUrl}"">View this {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} update</a>
</p>
<p>
    Please review this update and address the comments that {
                    returnerPerson.FirstName
                } left for you. If you have questions, please email: {returnerPerson.Email}
</p>
Thank you,<br />
{$"- {MultiTenantHelpers.GetToolDisplayName()} team"}
";

            var subject =
                $"The update for {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} {projectUpdateBatch.Project.GetDisplayName()} has been returned - please review and re-submit";
            var mailMessage = new MailMessage {
                Subject = subject, Body = message, IsBodyHtml = true
            };

            SendMessageAndLogNotificationForProjectUpdateTransition(projectUpdateBatch,
                                                                    mailMessage,
                                                                    emailsToSendTo,
                                                                    new List <string> {
                returnerPerson.Email
            },
                                                                    peopleToCc.Select(x => x.Email).ToList(),
                                                                    NotificationType.ProjectUpdateReturned);
        }
        public static void SendApprovalMessage(List <Person> peopleToCc, ProjectUpdateBatch projectUpdateBatch)
        {
            Check.Require(projectUpdateBatch.ProjectUpdateState == ProjectUpdateState.Approved, "Need to be in Approved state to send the Approved email!");
            var latestProjectUpdateHistorySubmitted = projectUpdateBatch.GetLatestProjectUpdateHistorySubmitted();
            var submitterPerson = latestProjectUpdateHistorySubmitted.UpdatePerson;
            var emailsToSendTo  = new List <string> {
                submitterPerson.Email
            };

            var personNames          = submitterPerson.GetFullNameFirstLast();
            var primaryContactPerson = projectUpdateBatch.Project.GetPrimaryContact();

            if (primaryContactPerson != null && !String.Equals(primaryContactPerson.Email, submitterPerson.Email, StringComparison.InvariantCultureIgnoreCase))
            {
                emailsToSendTo.Add(primaryContactPerson.Email);
                personNames += $" and {primaryContactPerson.GetFullNameFirstLast()}";
            }
            var contactsWhoCanManageProject = projectUpdateBatch.Project.GetContactsWhoCanManageProject();

            foreach (var contact in contactsWhoCanManageProject)
            {
                if (!string.Equals(contact.Email, submitterPerson.Email, StringComparison.InvariantCultureIgnoreCase) && (primaryContactPerson == null || !string.Equals(contact.Email, primaryContactPerson.Email, StringComparison.InvariantCultureIgnoreCase)))
                {
                    emailsToSendTo.Add(contact.Email);
                    personNames += $" and {contact.GetFullNameFirstLast()}";
                }
            }

            var approverPerson = projectUpdateBatch.LastUpdatePerson;
            var detailUrl      = SitkaRoute <ProjectController> .BuildAbsoluteUrlHttpsFromExpression(x => x.Detail(projectUpdateBatch.Project));

            var message = $@"
Dear {personNames},
<p>
    The update submitted for {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} {projectUpdateBatch.Project.GetDisplayName()} on {
                    latestProjectUpdateHistorySubmitted.TransitionDate.ToStringDate()
                } was approved by {approverPerson.GetFullNameFirstLastAndOrg()}.
</p>
<p>
    There is no action for you to take - this is simply a notification email. The updates for this {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} are now visible to the general public on this {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()}'s detail page:
</p>
<p>
    <a href=""{detailUrl}"">View this {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()}</a>
</p>
Thank you for keeping your {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} information and accomplishments up to date!<br />
{$"- {MultiTenantHelpers.GetToolDisplayName()} team"}
";

            var subject     = $"The update for {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} {projectUpdateBatch.Project.GetDisplayName()} was approved";
            var mailMessage = new MailMessage {
                Subject = subject, Body = message, IsBodyHtml = true
            };

            SendMessageAndLogNotificationForProjectUpdateTransition(projectUpdateBatch,
                                                                    mailMessage,
                                                                    emailsToSendTo,
                                                                    new List <string> {
                approverPerson.Email
            },
                                                                    peopleToCc.Select(x => x.Email).ToList(),
                                                                    NotificationType.ProjectUpdateApproved);
        }
Esempio n. 6
0
 public static DateTime?GetLatestSubmittalDate(this ProjectUpdateBatch projectUpdateBatch) => projectUpdateBatch.GetLatestProjectUpdateHistorySubmitted()?.TransitionDate;