Пример #1
0
 public bool DeleteEmailTemplate(EmailTemplateObject emailTemplate)
 {
     try
     {
         Config.Conn.Execute("DELETE FROM dat_EmailTemplate WHERE EmailTemplateId = @EmailTemplateId", emailTemplate);
     }
     catch (Exception ex)
     {
         ErrorLogObject.LogError("EmailTemplateObject::DeleteEmailTemplate", ex);
         return(false);
     }
     return(true);
 }
Пример #2
0
        public static bool SendEmail(SortMainObject sort, EmailTypeEnum emailType, bool includeAuthors, ref string errorMsg)
        {
            try
            {
                var template = EmailTemplateObject.GetEmailTemplate(emailType.ToString());
                if (template != null)
                {
                    string subject = template.Header.Replace("{STI_Number}", sort.TitleStr).Replace("{PublishTitle}", sort.PublishTitle);
                    string body    = template.Body
                                     .Replace("{STI_Number}", sort.TitleStr)
                                     .Replace("{PublishTitle}", sort.PublishTitle)
                                     .Replace("{Authors}", string.Join(", ", sort.Authors.Select(n => $"{n.FirstName} {n.LastName}")))
                                     .Replace("{DueDate}", $"{sort.DueDate:d}")
                                     .Replace("{ReviewStatus}", sort.ReviewStatus)
                                     .Replace("{ReviewProgress}", $"{sort.ReviewProgress:P}")
                                     .Replace("{ViewUrl}", $"<a href=\"{Config.SortUrl(false).TrailingForwardSlash()}Artifact/{sort.SortMainId}\">STI Artifact</a>")
                                     .Replace("{EditUrl}", $"<a href=\"{Config.SortUrl(false).TrailingForwardSlash()}Artifact/Edit/{sort.SortMainId}\">STI Artifact</a>");

                    if (emailType == EmailTypeEnum.FirstYearReminder || emailType == EmailTypeEnum.DelayedReminder)
                    {
                        return(SendReleaseOfficerEmail(sort, subject, body, emailType, ref errorMsg));
                    }

                    return(SendOwnerEmail(sort, subject, body, includeAuthors, emailType, ref errorMsg));
                }

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

            return(false);
        }
Пример #3
0
 public EmailTemplateObject SaveEmailTemplate(EmailTemplateObject emailTemplate)
 {
     if (emailTemplate.EmailTemplateId > 0) // Update
     {
         string sql = @"
             UPDATE  dat_EmailTemplate
             SET     EmailType = @EmailType,
                     Header = @Header,
                     Body = @Body,
                     EditedByEmployeeId = @EditedByEmployeeId,
                     LastEditDate = @LastEditDate
             WHERE   EmailTemplateId = @EmailTemplateId";
         Config.Conn.Execute(sql, emailTemplate);
     }
     else
     {
         string sql = @"
             INSERT INTO dat_EmailTemplate (
                 EmailType,
                 Header,
                 Body,
                 EditedByEmployeeId,
                 LastEditDate
             )
             VALUES (
                 @EmailType,
                 @Header,
                 @Body,
                 @EditedByEmployeeId,
                 @LastEditDate
             )
             SELECT CAST(SCOPE_IDENTITY() AS INT)";
         emailTemplate.EmailTemplateId = Config.Conn.Query <int>(sql, emailTemplate).Single();
     }
     return(emailTemplate);
 }