Ejemplo n.º 1
0
        public JsonResult UpdateTemplate(MailTemplate template)
        {
            if (template.Id < 1)
            {
                // New Item
                if (User.Templates.Any(x => x.Name.ToLower() == template.Name.ToLower()))
                {
                    return Json(false);
                }

                template.UpdateAttachments();
                User.AddTemplate(template);
            }
            else
            {
                // Update Item
                var temp = Repository.GetById<MailTemplate>(template.Id);
                temp.Name = template.Name;
                temp.Text = template.Text;
                temp.Subject = template.Subject;
                temp.Attachments.Clear();
                foreach (var attachment in template.Attachments)
                {
                    if (attachment.Id < 1)
                    {
                        temp.AddAttachment(attachment);
                    }
                    else
                    {
                        temp.Attachments.Add(Repository.GetById<Attachment>(attachment.Id));
                    }
                }
            }

            return Json(true);
        }
Ejemplo n.º 2
0
 public virtual void AddTemplate(MailTemplate template)
 {
     template.User = this;
     Templates.Add(template);
 }
        private MailMessage CreateMail(Contact contact, MailTemplate template)
        {
            var message = new MailMessage();

            message.Subject = GetCompleteText(contact, template.Subject);
            message.SubjectEncoding = Encoding.UTF8;

            message.Body = GetCompleteText(contact, template.Text);
            message.BodyEncoding = Encoding.UTF8;
            message.IsBodyHtml = true;

            foreach (var attachment in template.Attachments)
            {
                var stream = new MemoryStream(attachment.Content);
                var mailAttachment = new System.Net.Mail.Attachment(stream, attachment.Name, attachment.ContentType);
                message.Attachments.Add(mailAttachment);
            }

            message.From = new MailAddress(User.Settings.EmailAddressFrom);
            message.To.Add(new MailAddress(contact.Email));
            return message;
        }
Ejemplo n.º 4
0
 public JsonResult DeleteTemplate(MailTemplate template)
 {
     var temp = Repository.GetById<MailTemplate>(template.Id);
     Repository.Delete(temp);
     return Json(true);
 }