public static CallResult <ComposeEmailViewModel> FromTemplate(IUnitOfWork db,
                                                                      IEmailService emailService,
                                                                      string orderId,
                                                                      CompanyDTO company,
                                                                      string byName,
                                                                      EmailTypes type,
                                                                      EmailAccountDTO emailAccountInfo)
        {
            try
            {
                ComposeEmailViewModel model = new ComposeEmailViewModel();

                orderId = OrderHelper.RemoveOrderNumberFormat(orderId);

                var order = db.Orders.GetAll().FirstOrDefault(q => q.AmazonIdentifier.ToLower() == orderId || q.CustomerOrderId == orderId);

                if (order != null)
                {
                    IEmailInfo info = emailService.GetEmailInfoByType(db,
                                                                      type,
                                                                      company,
                                                                      byName,
                                                                      order?.AmazonIdentifier,
                                                                      new Dictionary <string, string>(),
                                                                      null,
                                                                      null);

                    model = ComposeEmailViewModel.BuildFrom(db, info);
                }

                model.FromName  = emailAccountInfo.DisplayName;
                model.FromEmail = emailAccountInfo.FromEmail;

                if (!StringHelper.ContainsNoCase(model.Subject, "[Important]") &&
                    (model.Market == MarketType.Amazon ||
                     model.Market == MarketType.AmazonEU ||
                     model.Market == MarketType.AmazonAU ||
                     model.Market == MarketType.None))
                {
                    var existEmailFromCustomer = db.Emails.GetAll().Any(e => e.From == model.ToEmail);
                    if (!existEmailFromCustomer)
                    {
                        model.Subject = "[Important] " + model.Subject;
                    }
                }

                return(CallResult <ComposeEmailViewModel> .Success(model));
            }
            catch (Exception ex)
            {
                return(CallResult <ComposeEmailViewModel> .Fail(ex.Message, ex));
            }
        }
        public object PostAddEdit(EmailAccountDTO EmailAccountDTO)
        {
            if (ModelState.IsValid)
            {
                sysBpmsEmailAccount emailAccount    = new sysBpmsEmailAccount();
                ResultOperation     resultOperation = emailAccount.Update((int)sysBpmsEmailAccount.e_ObjectTypeLU.Systemic, null, EmailAccountDTO.SMTP, EmailAccountDTO.Port,
                                                                          EmailAccountDTO.MailPassword, EmailAccountDTO.Email);

                if (!resultOperation.IsSuccess)
                {
                    return(new PostMethodMessage(resultOperation.GetErrors(), DisplayMessageType.error));
                }

                emailAccount.ID = EmailAccountDTO.ID;
                using (EmailAccountService EmailAccountService = new EmailAccountService())
                {
                    if (emailAccount.ID != Guid.Empty)
                    {
                        resultOperation = EmailAccountService.Update(emailAccount);
                    }
                    else
                    {
                        resultOperation = EmailAccountService.Add(emailAccount);
                    }
                }

                if (resultOperation.IsSuccess)
                {
                    return(new PostMethodMessage(SharedLang.Get("Success.Text"), DisplayMessageType.success));
                }
                else
                {
                    return(new PostMethodMessage(resultOperation.GetErrors(), DisplayMessageType.error));
                }
            }
            else
            {
                return(new PostMethodMessage(SharedLang.Get("NotFound.Text"), DisplayMessageType.error));
            }
        }
 public object TestEmail(EmailAccountDTO EmailAccountDTO)
 {
     if (ModelState.IsValid)
     {
         ResultOperation resultOperation = new EmailService().SendEmail(EmailAccountDTO.Email, EmailAccountDTO.MailPassword, EmailAccountDTO.SMTP, EmailAccountDTO.Port.ToIntObj(), new List <string>()
         {
             EmailAccountDTO.Email
         }, "", "", "Test Email", "This is a test");
         if (resultOperation.IsSuccess)
         {
             return(new PostMethodMessage(SharedLang.Get("Success.Text"), DisplayMessageType.success));
         }
         else
         {
             return(new PostMethodMessage("Test failed.", DisplayMessageType.error));
         }
     }
     else
     {
         return(new PostMethodMessage(SharedLang.Get("NotFound.Text"), DisplayMessageType.error));
     }
 }
        public static CallResult <ComposeEmailViewModel> GetTemplateInfo(IUnitOfWork db,
                                                                         IEmailService emailService,
                                                                         CompanyDTO company,
                                                                         string byName,
                                                                         EmailTypes type,
                                                                         EmailAccountDTO emailAccountInfo,
                                                                         string orderNumber,
                                                                         long?replyToId)
        {
            var model  = new ComposeEmailViewModel();
            var result = CallResult <ComposeEmailViewModel> .Success(model);

            if (!String.IsNullOrEmpty(orderNumber))
            {
                result = ComposeEmailViewModel.FromTemplate(db,
                                                            emailService,
                                                            orderNumber,
                                                            company,
                                                            byName,
                                                            (EmailTypes)type,
                                                            emailAccountInfo);

                if (result.IsSuccess)
                {
                    model = result.Data;
                }
            }

            var useReSubject = false;

            if (replyToId.HasValue)
            {
                var replyToEmail = db.Emails.Get(replyToId.Value);
                if (replyToEmail != null)
                {
                    model.Subject = "RE: " + replyToEmail.Subject;

                    if (String.IsNullOrEmpty(model.Body)) //For Custom template
                    {
                        model.Body = "<br/><br/><br/><br/>";
                    }
                    model.Body = model.Body + "<hr/><br/>" + replyToEmail.Message;

                    if (replyToEmail.From != "*****@*****.**" &&
                        !(StringHelper.ContainsNoCase(replyToEmail.From, "@walmart.com") &&
                          StringHelper.ContainsNoCase(replyToEmail.Subject, "Walmart Escalation")))      //NOTE: when reply to walmart support email do not use them
                    {
                        model.ToEmail = replyToEmail.From;
                    }

                    useReSubject = true;
                }
            }

            if ((model.Market == MarketType.Amazon ||
                 model.Market == MarketType.AmazonEU ||
                 model.Market == MarketType.AmazonAU))
            {
                if (!useReSubject)
                {
                    if (StringHelper.ContainsNoCase(model.Subject, "[Important]"))
                    {
                        model.Subject = "[Important] ";
                    }
                    else
                    {
                        model.Subject = "";
                    }
                    model.Subject += "Additional Information Required (Order: " + orderNumber + ")";
                }
            }

            model.FromName  = emailAccountInfo.DisplayName;
            model.FromEmail = emailAccountInfo.FromEmail;

            model.ReplyToEmailId = replyToId;

            return(result);
        }
Esempio n. 5
0
 public EmailDTO()
 {
     From = new EmailAccountDTO();
     To   = new EmailAccountDTO();
 }