コード例 #1
0
        public ActionResult SaveClone(EmailTemplate model)
        {
            DBEntities e = COREobject.i.Context;

            if (ModelState.IsValid)
            {
                EmailTemplate row = e.EmailTemplates.Include("PlaceholderList").Include("ContentList").Single(m => m.Id == model.Id);

                // Naklonujeme šablonu
                EmailTemplate newRow = new EmailTemplate();
                newRow.Name    = model.Name;
                newRow.AppId   = model.AppId;
                newRow.Is_HTML = model.Is_HTML;

                e.EmailTemplates.Add(newRow);
                e.SaveChanges();

                // Naklonujeme proměnné
                foreach (EmailPlaceholder plc in row.PlaceholderList)
                {
                    EmailPlaceholder newPlc = new EmailPlaceholder();
                    newPlc.Description = plc.Description;
                    newPlc.Hermes_Email_Template_Id = newRow.Id;
                    newPlc.Num_Order = plc.Num_Order;
                    newPlc.Prop_Name = plc.Prop_Name;

                    e.EmailPlaceholders.Add(newPlc);
                }

                // Naklonujeme content
                foreach (EmailTemplateContent content in row.ContentList)
                {
                    EmailTemplateContent newContent = new EmailTemplateContent();
                    newContent.Content                  = content.Content;
                    newContent.Content_Plain            = content.Content_Plain;
                    newContent.From_Email               = content.From_Email;
                    newContent.From_Name                = content.From_Name;
                    newContent.Hermes_Email_Template_Id = newRow.Id;
                    newContent.LanguageId               = content.LanguageId;
                    newContent.Subject                  = content.Subject;

                    e.EmailContents.Add(newContent);
                }

                e.SaveChanges();

                return(RedirectToRoute("Hermes", new { @action = "Index" }));
            }
            else
            {
                return(View("~/Views/Hermes/Template/Form.cshtml", model));
            }
        }
コード例 #2
0
        public void CreateEmailReturnsEmailsWithNotEmptyBodyAndUnknownPlaceholdersAreNotReplaced()
        {
            var unknownPlaceholder = "{PLACEHOLDER}";
            var templateContent    = new EmailTemplateContent("test subject", $"Hello {unknownPlaceholder}");

            var emails = _byUserEmailFactory.CreateEmails(templateContent, TestEmailContext).ToList();

            for (int i = 0; i < TestEmailContext.Users.Count; i++)
            {
                Assert.Contains(unknownPlaceholder, emails[i].Body);
            }
        }
コード例 #3
0
        public void CreateEmailReturnsEmailsWithNotEmptyBodyAndUserNamePlaceholdersAreReplacedByActualUserNames()
        {
            var userNamePlaceholder = _byUserEmailFactory.Placeholders["UserName"];
            var templateContent     = new EmailTemplateContent("test subject", $"Hello {userNamePlaceholder}");

            var emails = _byUserEmailFactory.CreateEmails(templateContent, TestEmailContext).ToList();

            for (int i = 0; i < TestEmailContext.Users.Count; i++)
            {
                Assert.DoesNotContain(userNamePlaceholder, emails[i].Body);
                Assert.Contains(TestEmailContext.Users[i].Name, emails[i].Body);
            }
        }
コード例 #4
0
ファイル: Mailer.cs プロジェクト: taquinil-selei/omnius
        public void Prepare(string templateName, Object model)
        {
            data = model;

            EmailTemplate template = e.EmailTemplates.Single(t => t.Name == templateName);

            plcs = template.PlaceholderList.OrderBy(p => p.Num_Order).ToList();
            EmailTemplateContent contentModel = template.ContentList.Single(t => t.LanguageId == (int)mailerLanguage);

            string subject = SetData(contentModel.Subject);
            string content = SetData(contentModel.Content);

            mail = new MailMessage();
            mail.BodyEncoding = UTF8Encoding.UTF8;
            mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

            if (!string.IsNullOrWhiteSpace(contentModel.From_Email))
            {
                mail.From = new MailAddress(contentModel.From_Email, contentModel.From_Name);
            }
            else
            {
                OmniusException.Log("Nutno vyplnit email odesílatele.");
            }

            if (!string.IsNullOrWhiteSpace(subject))
            {
                mail.Subject = subject;
            }

            if (!string.IsNullOrWhiteSpace(content))
            {
                mail.Body = content;
            }

            if (template.Is_HTML)
            {
                mail.IsBodyHtml = true;
                if (!string.IsNullOrWhiteSpace(contentModel.Content_Plain))
                {
                    string contentPlain = SetData(contentModel.Content_Plain);
                    mail.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(contentPlain, Encoding.UTF8, MediaTypeNames.Text.Plain));
                }
                mail.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(content, Encoding.UTF8, MediaTypeNames.Text.Html));
            }
        }
コード例 #5
0
        public ActionResult SaveContent(EmailTemplate model)
        {
            DBEntities e = COREobject.i.Context;

            if (!model.Id.Equals(null))
            {
                EmailTemplate row = e.EmailTemplates.Single(m => m.Id == model.Id);

                NameValueCollection form = Request.Unvalidated.Form;
                foreach (KeyValuePair <int, string> lang in LanguageList)
                {
                    int    langId = lang.Key;
                    string lId    = langId.ToString();

                    EmailTemplateContent contentModel = row.ContentList.SingleOrDefault(c => c.LanguageId == langId);
                    bool exists = contentModel != null;

                    if (!exists)
                    {
                        contentModel = new EmailTemplateContent();
                    }

                    contentModel.LanguageId = langId;
                    contentModel.Hermes_Email_Template_Id = row.Id;
                    contentModel.From_Name     = form["content.From_Name." + lId];
                    contentModel.From_Email    = form["content.From_Email." + lId];
                    contentModel.Subject       = form["content.Subject." + lId];
                    contentModel.Content       = form["content.Content." + lId];
                    contentModel.Content_Plain = form["content.Content_Plain." + lId];

                    if (!exists)
                    {
                        row.ContentList.Add(contentModel);
                    }
                }
                e.SaveChanges();
            }
            else
            {
                throw new System.Exception("Požadovaná šablona neexistuje.");
            }

            return(RedirectToRoute("Hermes", new { @action = "Index" }));
        }
コード例 #6
0
        public override IEnumerable <Email> CreateEmails(EmailTemplateContent templateContent, EmailContext context)
        {
            var emails = new List <Email>();

            foreach (var user in context.Users)
            {
                var emailBody = templateContent.Text.Replace(Placeholders["UserName"], user.Name);
                var email     = new Email
                {
                    ToAddress = user.EmailAddress,
                    Subject   = templateContent.Subject,
                    Body      = emailBody
                };

                emails.Add(email);
            }

            return(emails);
        }
コード例 #7
0
        public override IEnumerable <Email> CreateEmails(EmailTemplateContent templateContent, EmailContext context)
        {
            var emails = new List <Email>();

            var email = new Email
            {
                Subject = templateContent.Subject,
                Body    = templateContent.Text
            };

            foreach (var user in context.Users)
            {
                email.BCCAddresses.Add(user.EmailAddress);
            }

            emails.Add(email);

            return(emails);
        }
コード例 #8
0
        public ByUserEmailFactoryTests()
        {
            _byUserEmailFactory = new ByUserEmailFactory();

            TestEmailContext = new EmailContext();
            TestEmailContext.Users.Add(new User()
            {
                Name = "test user 1", EmailAddress = "*****@*****.**"
            });
            TestEmailContext.Users.Add(new User()
            {
                Name = "test user 2", EmailAddress = "*****@*****.**"
            });
            TestEmailContext.Users.Add(new User()
            {
                Name = "test user 3", EmailAddress = "*****@*****.**"
            });
            TestEmailContext.Users.Add(new User()
            {
                Name = "test user 4", EmailAddress = "*****@*****.**"
            });

            TestEmailTemplateContent = new EmailTemplateContent("test subject", "test text");
        }
コード例 #9
0
        public CommonEmailFactoryTests()
        {
            _commonEmailFactory = new CommonEmailFactory();

            TestEmailTemplateContent = new EmailTemplateContent("test subject", "test text");
        }
コード例 #10
0
ファイル: EmailFactory.cs プロジェクト: Lunitor/Notification
 public abstract IEnumerable <Email> CreateEmails(EmailTemplateContent templateContent, EmailContext context);
コード例 #11
0
ファイル: EmailTemplate.cs プロジェクト: Lunitor/Notification
 public EmailTemplate(string type, string subject, string text)
 {
     Type    = type;
     Content = new EmailTemplateContent(subject, text);
 }
コード例 #12
0
ファイル: EmailTemplate.cs プロジェクト: Lunitor/Notification
 public EmailTemplate(string type, EmailTemplateContent templateContent)
 {
     Type    = type;
     Content = templateContent;
 }
コード例 #13
0
        private void BuildHermes()
        {
            progressHandler.SetActiveSection(EModule.Hermes);

            if (context != masterContext)
            {
                try
                {
                    progressHandler.SetMessage(type: MessageType.Info, message: "Copying email templates");

                    // remove old
                    context.EmailPlaceholders.RemoveRange(context.EmailPlaceholders.Where(ep => ep.Hermes_Email_Template.AppId == app.Id));
                    context.EmailContents.RemoveRange(context.EmailContents.Where(ec => ec.Hermes_Email_Template.AppId == app.Id));
                    context.EmailTemplates.RemoveRange(app.EmailTemplates);

                    // add new
                    foreach (EmailTemplate template in masterApp.EmailTemplates)
                    {
                        EmailTemplate newTemplate = new EmailTemplate
                        {
                            Application = app,
                            Is_HTML     = template.Is_HTML,
                            Name        = template.Name
                        };

                        foreach (EmailPlaceholder placeholder in template.PlaceholderList)
                        {
                            EmailPlaceholder newPlaceholder = new EmailPlaceholder
                            {
                                Description = placeholder.Description,
                                Num_Order   = placeholder.Num_Order,
                                Prop_Name   = placeholder.Prop_Name
                            };
                            newTemplate.PlaceholderList.Add(newPlaceholder);
                        }
                        foreach (EmailTemplateContent content in template.ContentList)
                        {
                            EmailTemplateContent newContent = new EmailTemplateContent
                            {
                                Content       = content.Content,
                                Content_Plain = content.Content_Plain,
                                From_Email    = content.From_Email,
                                From_Name     = content.From_Name,
                                LanguageId    = content.LanguageId,
                                Subject       = content.Subject
                            };
                            newTemplate.ContentList.Add(newContent);
                        }

                        context.EmailTemplates.Add(newTemplate);
                    }
                    context.SaveChanges();

                    progressHandler.SetMessage(type: MessageType.Success, message: "Copying email templates completed");
                }
                catch (Exception ex)
                {
                    progressHandler.Error(ex.Message);
                }
            }
            else
            {
                progressHandler.SetMessage(type: MessageType.Info, message: "Copying email templates is not necessary to generate");
            }
        }