Ejemplo n.º 1
0
        public virtual MvcMailMessage SendEmail(IEmailInfo emailInfo)
        {
            ViewData.Model = emailInfo;
            return(Populate(x =>
            {
                if (emailInfo.Sender != null)
                {
                    x.Sender = new MailAddress(emailInfo.Sender);
                }
                x.Subject = emailInfo.Subject;
                x.ViewName = emailInfo.ViewName;
                x.IsBodyHtml = true;
                x.To.Add(emailInfo.To);

                x.From = new MailAddress(emailInfo.From);
            }));
        }
        public static ComposeEmailViewModel BuildFrom(IUnitOfWork db, IEmailInfo emailInfo)
        {
            var model = new ComposeEmailViewModel();

            model.EmailType   = emailInfo.EmailType;
            model.OrderNumber = emailInfo.Tag;
            model.Market      = emailInfo.Market;

            if (emailInfo.From != null)
            {
                model.FromEmail = emailInfo.From.Address;
                model.FromName  = emailInfo.From.DisplayName;
            }

            if (emailInfo.ToList != null && emailInfo.ToList.Count > 0)
            {
                model.ToEmail = emailInfo.ToList[0].Address;
                model.ToName  = emailInfo.ToList[0].DisplayName;
            }

            model.Body    = emailInfo.Body;
            model.Subject = emailInfo.Subject;

            var order = db.Orders.GetByCustomerOrderNumber(emailInfo.Tag);

            if (order != null)
            {
                var label = db.Labels.GetByOrderIdAsDto(order.Id)
                            .OrderByDescending(l => l.LabelPurchaseDate)
                            .FirstOrDefault(l => !String.IsNullOrEmpty(l.TrackingNumber));
                if (label != null)
                {
                    model.ShipmentProvider = (ShipmentProviderType)label.ShipmentProviderType;
                }
            }

            return(model);
        }