public async Task<Message> ComposeRepairCompletedEmailMessage(int incidentId)
        {
            var incident = await GetIncident(incidentId);
            var attachments = await GetInspectionOrRepairPhotosAsAttachments("Room Inspection Photos", incident.sl_inspectionID.Id, incident.sl_roomID.Id);

            var property = incident.sl_propertyID;

            var propertyOwnerRecipientEmail = new EmailAddress { Address = property.sl_emailaddress, Name = property.sl_owner };
            var dispacherRecipientEmail = new EmailAddress { Address = DispatcherEmail, Name = DispatcherName };

            var bodyTemplate = System.IO.File.ReadAllText(bodyTemplateFile);
            var viewBag = new RazorEngine.Templating.DynamicViewBag();
            viewBag.AddValue("InspectionPhotosAttachments", attachments);
            var body = RazorEngine.Razor.Parse(bodyTemplate, incident, viewBag, "EmailBody");

            var message = new Message
            {
                Subject = string.Format("Repair Report - {0} - {1:MM/dd/yyyy}", property.Title, DateTime.UtcNow),
                Importance = Importance.Normal,
                Body = new ItemBody
                {
                    ContentType = BodyType.HTML,
                    Content = body
                },
            };
            message.ToRecipients.Add(new Recipient { EmailAddress = propertyOwnerRecipientEmail });
            message.CcRecipients.Add(new Recipient { EmailAddress = dispacherRecipientEmail });
            foreach (var attachment in attachments)
                message.Attachments.Add(attachment);

            return message;
        }
示例#2
0
 /// <summary>
 /// Define os dados para template.
 /// </summary>
 /// <param name="model"></param>
 /// <param name="viewbag"></param>
 public override void SetData(object model, RazorEngine.Templating.DynamicViewBag viewbag)
 {
     _viewContext = viewbag is CustomDynamicViewBag ? ((CustomDynamicViewBag)viewbag).ViewContext : null;
     if (_viewContext != null)
     {
         Url  = new UrlHelper(_viewContext.RequestContext, System.Web.Routing.RouteTable.Routes);
         Html = new HtmlHelper <object>(_viewContext, new ViewDataContainer(_viewContext));
     }
     base.SetData(model, viewbag);
 }
        public async Task <Message> ComposeRepairCompletedEmailMessage(int incidentId)
        {
            var incident = await GetIncident(incidentId);

            var attachments = await GetInspectionOrRepairPhotosAsAttachments("Room Inspection Photos", incident.sl_inspectionID.Id, incident.sl_roomID.Id);

            var property = incident.sl_propertyID;

            var propertyOwnerRecipientEmail = new EmailAddress {
                Address = property.sl_emailaddress, Name = property.sl_owner
            };
            var dispacherRecipientEmail = new EmailAddress {
                Address = DispatcherEmail, Name = DispatcherName
            };

            var bodyTemplate = System.IO.File.ReadAllText(bodyTemplateFile);
            var viewBag      = new RazorEngine.Templating.DynamicViewBag();

            viewBag.AddValue("InspectionPhotosAttachments", attachments);
            var body = RazorEngine.Razor.Parse(bodyTemplate, incident, viewBag, "EmailBody");

            var message = new Message
            {
                Subject    = string.Format("Repair Report - {0} - {1:MM/dd/yyyy}", property.Title, DateTime.UtcNow),
                Importance = Importance.Normal,
                Body       = new ItemBody
                {
                    ContentType = BodyType.HTML,
                    Content     = body
                },
            };

            message.ToRecipients.Add(new Recipient {
                EmailAddress = propertyOwnerRecipientEmail
            });
            message.CcRecipients.Add(new Recipient {
                EmailAddress = dispacherRecipientEmail
            });
            foreach (var attachment in attachments)
            {
                message.Attachments.Add(attachment);
            }

            return(message);
        }
 /// <summary>
 /// Cria a instancia com base em outro viewbag.
 /// </summary>
 /// <param name="viewbag"></param>
 public CustomDynamicViewBag(RazorEngine.Templating.DynamicViewBag viewbag) : base(viewbag)
 {
 }