Exemplo n.º 1
0
 public bool DeleteEmailTemplate(EmailTemplateObject emailTemplate)
 {
     try
     {
         Config.Conn.Execute("DELETE FROM dat_EmailTemplate WHERE EmailTemplateId = @EmailTemplateId", emailTemplate);
     }
     catch { return(false); }
     return(true);
 }
Exemplo n.º 2
0
 public EmailTemplateObject SaveEmailTemplate(EmailTemplateObject emailTemplate)
 {
     if (emailTemplate.EmailTemplateId > 0) // Update
     {
         string sql = @"
             UPDATE  dat_EmailTemplate
             SET     Header = @Header,
                     Body = @Body,
                     EditedByEmployeeId = @EditedByEmployeeId,
                     LastEditDate = @LastEditDate,
                     IncludeAuthors = @IncludeAuthors,
                     IncludeContacts = @IncludeContacts
             WHERE   EmailTemplateId = @EmailTemplateId";
         Config.Conn.Execute(sql, emailTemplate);
     }
     else
     {
         string sql = @"
             INSERT INTO dat_EmailTemplate (
                 EmailType,
                 Header,
                 Body,
                 EditedByEmployeeId,
                 LastEditDate,
                 IncludeAuthors,
                 IncludeContacts
             )
             VALUES (
                 @EmailType,
                 @Header,
                 @Body,
                 @EditedByEmployeeId,
                 @LastEditDate,
                 @IncludeAuthors,
                 @IncludeContacts
             )
             SELECT CAST(SCOPE_IDENTITY() AS INT)";
         emailTemplate.EmailTemplateId = Config.Conn.Query <int>(sql, emailTemplate).Single();
     }
     return(emailTemplate);
 }
Exemplo n.º 3
0
        public static bool SendEmail(MainObject main, ReviewObject review, EmailTypeEnum emailType, string comment, ref string errorMsg)
        {
            try
            {
                var template = EmailTemplateObject.GetEmailTemplate(emailType);
                if (template != null)
                {
                    string subject = template.Header.Replace("{STI_Number}", main.StiNumber ?? string.Empty).Replace("{Title}", main.Title ?? string.Empty);
                    string body    = ConstructBody(main, review, comment, template);
                    switch (emailType)
                    {
                    case EmailTypeEnum.ReleaseOfficerComplete:
                        return(SendReleaseOfficerEmail(subject, body, ref errorMsg));

                    case EmailTypeEnum.ClassReviewer:
                    case EmailTypeEnum.ExportReviewer:
                    case EmailTypeEnum.ManagerReviewer:
                    case EmailTypeEnum.PeerReviewer:
                    case EmailTypeEnum.TechReviewer:
                    case EmailTypeEnum.ReviewReminder:
                        return(review != null?SendReviewerEmail(review, subject, body, ref errorMsg) : SendReviewersEmail(main, subject, body, emailType, ref errorMsg));

                    default:
                        return(SendOwnerEmail(main, subject, body, template.IncludeAuthors, template.IncludeContacts, ref errorMsg));
                    }
                }

                errorMsg = $"Unable to find the Template for Email Type: {emailType}";
            }
            catch (Exception ex)
            {
                errorMsg = $"Exception Caught while attempting to send an email: {ex.Message}";
            }

            return(false);
        }
Exemplo n.º 4
0
        private static string ConstructBody(MainObject main, ReviewObject review, string comment, EmailTemplateObject template)
        {
            if (template != null)
            {
                return(template.Body
                       .Replace("{STI_Number}", main.StiNumber ?? string.Empty)
                       .Replace("{Title}", main.Title ?? string.Empty)
                       .Replace("{Authors}", string.Join(", ", main.Authors.Select(n => n.Name)) ?? string.Empty)
                       //.Replace("{DueDate}", $"{main.DueDate:d}")
                       .Replace("{ReviewStatus}", main.ReviewStatus ?? string.Empty)
                       .Replace("{ReviewProgress}", $"{main.ReviewProgress:P}" ?? string.Empty)
                       .Replace("{ReviewerName}", review?.ReviewerName ?? string.Empty)
                       .Replace("{Comment}", comment ?? string.Empty)
                       .Replace("{ReviewType}", review?.ReviewerTypeDisplayName ?? string.Empty)
                       .Replace("{Url}", $"<a href=\"{Config.SiteUrl.TrailingSlash()}Artifact/Index/{main.MainId}\">LRS Artifact</a>")
                       .Replace("{OUO-FOIA}", main.OuoEmailText ?? string.Empty)
                       .Replace("{FundingOrg}", string.Join(", ", main?.Funding?.Where(m => !string.IsNullOrWhiteSpace(m.FundingOrgName)).Select(n => n.FundingOrgName)) ?? string.Empty));
            }

            return(string.Empty);
        }