Пример #1
0
        public void SendEmail(SendEmailParameter param)
        {
            var client = GetMailClient(param);

            foreach (string to in param.Recipients)
            {
                client.AddTo(to, string.Empty);
            }
            client.SetBody(param.Subject, param.Body);
            object userToken = null;

            if (_config.LogEmail)
            {
                using (var context = base.CreateContext())
                {
                    var pObj = new EmailMessage();
                    EntityMapper.Map <SendEmailParameter, EmailMessage>(param, pObj);
                    pObj.RowID      = Guid.NewGuid();
                    pObj.From       = client.From.Address;
                    pObj.To         = string.Join(";", param.Recipients);
                    pObj.CreateDate = DateTime.Now;
                    pObj.Status     = (int)MessageStatusKind.Unsent;
                    context.EmailMessages.Add(pObj);
                    context.SaveChanges();

                    userToken = pObj.RowID;
                }
                client.SendCompleted += new System.Net.Mail.SendCompletedEventHandler(sender_SendCompleted);
            }

            client.SendAsync(userToken);
        }
        protected void SendOrderCancellationEmail(IUnitOfWork unitOfWork, CustomerOrder cart)
        {
            dynamic expandoObjects = new ExpandoObject();

            this.PopulateOrderEmailModel(expandoObjects, cart, unitOfWork);
            EmailList     orCreateByName = unitOfWork.GetTypedRepository <IEmailListRepository>().GetOrCreateByName("OrderCancellation", "Order Cancellation");
            List <string> list           = BuildEmailValues(cart.Id, unitOfWork).Split(new char[] { ',' }).ToList <string>();
            EmailList     emailList      = unitOfWork.GetRepository <EmailList>().GetTable().Expand((EmailList x) => x.EmailTemplate).FirstOrDefault((EmailList x) => x.Id == orCreateByName.Id);

            if (emailList != null)
            {
                SendEmailParameter sendEmailParameter = new SendEmailParameter();
                CustomSettings     customSettings     = new CustomSettings();
                string             htmlTemplate       = GetHtmlTemplate(emailList);
                sendEmailParameter.Body = this.EmailService.Value.ParseTemplate(htmlTemplate, expandoObjects);
                string defaultEmailAddress = customSettings.DefaultEmailAddress;
                string approverEmail       = SiteContext.Current.IsUserInRole("Administrator") ? SiteContext.Current.UserProfileDto.Email : !string.IsNullOrEmpty(cart.ApproverUserProfile.Email) ? cart.ApproverUserProfile.Email : defaultEmailAddress;// BUSA-625 : To Add Reject Button to order Approve page. If Admin rejects the order, then Admin email's address should be in From address.
                sendEmailParameter.Subject            = emailList.Subject;
                sendEmailParameter.ToAddresses        = list;
                sendEmailParameter.FromAddress        = approverEmail;
                sendEmailParameter.ReplyToAddresses   = new List <string>();
                sendEmailParameter.ExtendedProperties = new NameValueCollection();
                this.EmailService.Value.SendEmail(sendEmailParameter, unitOfWork);
            }
        }
Пример #3
0
        public void ResendFailEmail()
        {
            using (var context = base.CreateContext())
            {
                int      status = EnumToValue(MessageStatusKind.Error);
                DateTime start = DateTime.Now.AddDays(-1D), end = DateTime.Now.AddDays(1D);
                var      q = from t in context.EmailMessages
                             where t.Status == status &&
                             start <= t.CreateDate && t.CreateDate <= end
                             select t;
                foreach (var item in q)
                {
                    var param = new SendEmailParameter();
                    param.AppID      = item.AppID;
                    param.ConfigID   = _config.ResendFailEmailConfigID;
                    param.Recipients = item.To.Split(';');
                    param.Subject    = item.Subject;
                    param.Body       = item.Body;

                    var sender = GetMailClient(param);
                    foreach (string to in param.Recipients)
                    {
                        sender.AddTo(to, string.Empty);
                    }
                    sender.SetBody(param.Subject, param.Body);
                    sender.SendCompleted += new System.Net.Mail.SendCompletedEventHandler(sender_SendCompleted);
                    sender.SendAsync(item.RowID);

                    Thread.Sleep(200);
                }
            }
        }
Пример #4
0
        private MailClient GetMailClient(SendEmailParameter header)
        {
            base.VerifyHeader(header);

            using (var context = base.CreateContext())
            {
                var config = context.EmailConfigs.First(t => header.ConfigID == null || t.RowID == header.ConfigID);
                var client = new MailClient();
                var arr    = config.SmtpAuthority.Split(':');
                client.Config(arr[0], arr.Length == 2 ? int.Parse(arr[1]) : 25, config.EnableSsl, config.UserName, config.Password);
                client.SetFrom(config.FromEmail, config.FromDisplayName);
                return(client);
            }
        }
Пример #5
0
        public override TellAFriendResult TellAFriend(TellAFriendParameter parameter)
        {
            EmailList     orCreateByName  = UnitOfWork.GetTypedRepository <IEmailListRepository>().GetOrCreateByName(nameof(TellAFriend), "Your Friend has Sent You a Message", "");
            EmailList     emailList       = UnitOfWork.GetRepository <EmailList>().GetTable().Expand((EmailList x) => x.EmailTemplate).FirstOrDefault((EmailList x) => x.Id == orCreateByName.Id);
            List <string> toAddressesList = new List <string>();


            SendEmailParameter sendEmailParameter = new SendEmailParameter();

            foreach (var keyValue in parameter.EmailModel)
            {
                if (keyValue.Key.ToString().ToUpper().Equals("USERSEMAIL"))
                {
                    sendEmailParameter.FromAddress = keyValue.Value.ToString();
                }
                if (keyValue.Key.ToString().ToUpper().Equals("FRIENDSEMAIL"))
                {
                    toAddressesList.Add(keyValue.Value.ToString());
                }
            }

            string htmlTemplate = GetHtmlTemplate(emailList);

            sendEmailParameter.Body = this.EmailService.ParseTemplate(htmlTemplate, parameter.EmailModel);

            sendEmailParameter.Subject      = emailList.Subject;
            sendEmailParameter.BccAddresses = new List <string>();

            var emailCCAddresses = customSettings.EmailCCAddresses;

            if (!string.IsNullOrEmpty(emailCCAddresses))
            {
                sendEmailParameter.CCAddresses.Add(emailCCAddresses);
            }
            sendEmailParameter.ToAddresses        = toAddressesList;
            sendEmailParameter.ReplyToAddresses   = new List <string>();
            sendEmailParameter.ExtendedProperties = new NameValueCollection();

            this.EmailService.SendEmail(sendEmailParameter, this.UnitOfWork);

            return(new TellAFriendResult());
        }
Пример #6
0
        public void Execute(DataSet dataSet, CancellationToken cancellationToken)
        {
            LogHelper.For((object)this).Info("Post Processor start.");
            try
            {
                if (dataSet.Tables.Count > 0)
                {
                    using (var sqlConnection = new SqlConnection(InsiteDbConnectionString))
                    {
                        sqlConnection.Open();
                        const string createTempTableSql = @"Create table #BackOrderRefreshFilter 
                                                            (WebOrderNumber nvarchar(50),OrderNumber nvarchar(50), OrderGen nvarchar(50),ProductERPNumber nvarchar(50),
                                                            QtyOrdered decimal (18, 5), QtyShipped decimal (18, 5),QtyBO decimal(18, 5))";

                        using (var command = new SqlCommand(createTempTableSql, sqlConnection))
                        {
                            command.CommandTimeout = CommandTimeOut;
                            command.ExecuteNonQuery();
                        }
                        WriteToServer(sqlConnection, "tempdb..#BackOrderRefreshFilter", dataSet.Tables[0]);

                        const string backOrderCustomerList = @"select distinct OH.CustomerNumber, BORF.WebOrderNumber, BO.OrderLanguage  from
                                                                #BackOrderRefreshFilter as BORF 
                                                                join OrderHistory as OH on OH.WebOrderNumber= BORF.WebOrderNumber
                                                                left join  BackOrders BO on BO.WebOrderNumber = BORF.WebOrderNumber 
                                                                where  BO.CheckedForBO = 0   
                                                                Group by OH.CustomerNumber,BORF.WebOrderNumber, BO.OrderLanguage";

                        SqlDataAdapter da = new SqlDataAdapter(backOrderCustomerList, sqlConnection);
                        da.Fill(dataSet, "CustomerLists");

                        DataTable dt = new DataTable();
                        dt = dataSet.Tables["CustomerLists"];

                        foreach (DataRow dRow in dt.Rows)
                        {
                            string    emailBody    = string.Empty;
                            EmailList emailList    = null;
                            string    htmlTemplate = string.Empty;
                            dynamic   emailModel   = new ExpandoObject();

                            string webOrderNumber = dRow["WebOrderNumber"].ToString();
                            string customerNumber = dRow["CustomerNumber"].ToString();
                            string languageId     = dRow["OrderLanguage"].ToString();

                            var customer = this.UnitOfWork.GetRepository <Customer>().GetTable().FirstOrDefault(x => x.CustomerNumber == customerNumber);
                            if (!string.IsNullOrEmpty(customer.Email))
                            {
                                var orderHistory = this.UnitOfWork.GetRepository <OrderHistory>().GetTable().FirstOrDefault(x => x.WebOrderNumber == webOrderNumber);
                                var language     = this.UnitOfWork.GetRepository <Language>().GetTable().FirstOrDefault(x => x.Id.ToString() == languageId);
                                var salesRep     = this.UnitOfWork.GetRepository <Salesperson>().GetTable().FirstOrDefault(x => x.Name == orderHistory.Salesperson);

                                if (language.LanguageCode == "en-us")
                                {
                                    EmailList orCreateByName_USA = this.UnitOfWork.GetTypedRepository <IEmailListRepository>().GetOrCreateByName("BackOrderUSA", "Back Orders");
                                    emailList = this.UnitOfWork.GetRepository <EmailList>().GetTable().Expand((EmailList x) => x.EmailTemplate).FirstOrDefault((EmailList x) => x.Id == orCreateByName_USA.Id);
                                }
                                else if (language.LanguageCode == "en-CA")
                                {
                                    EmailList orCreateByName_CA = this.UnitOfWork.GetTypedRepository <IEmailListRepository>().GetOrCreateByName("BackOrderCA-EN", "Back Orders");
                                    emailList = this.UnitOfWork.GetRepository <EmailList>().GetTable().Expand((EmailList x) => x.EmailTemplate).FirstOrDefault((EmailList x) => x.Id == orCreateByName_CA.Id);
                                }
                                else
                                {
                                    EmailList orCreateByName_FR = this.UnitOfWork.GetTypedRepository <IEmailListRepository>().GetOrCreateByName("BackOrderCA-FR", "Back Orders");
                                    emailList = this.UnitOfWork.GetRepository <EmailList>().GetTable().Expand((EmailList x) => x.EmailTemplate).FirstOrDefault((EmailList x) => x.Id == orCreateByName_FR.Id);
                                }

                                htmlTemplate = GetHtmlTemplate(emailList);

                                this.PopulateDailyOrderEmailModel(emailModel, customer, orderHistory);

                                SendEmailParameter sendEmailParameter = new SendEmailParameter();
                                sendEmailParameter.ToAddresses.Add(customer.Email);
                                sendEmailParameter.Body        = this.EmailService.Value.ParseTemplate(htmlTemplate, emailModel);
                                sendEmailParameter.Subject     = emailList.Subject;
                                sendEmailParameter.FromAddress = (emailList.FromAddress.IsBlank() ? this.CustomSettings.DefaultEmailAddress : emailList.FromAddress);
                                if (!string.IsNullOrEmpty(salesRep.Email))
                                {
                                    sendEmailParameter.CCAddresses.Add(salesRep.Email);
                                }

                                this.EmailService.Value.SendEmail(sendEmailParameter, this.UnitOfWork);

                                const string mailSent = @"update BackOrders set CheckedForBO = 1 where WebOrderNumber = @WebOrderNumber";

                                using (var command = new SqlCommand(mailSent, sqlConnection))
                                {
                                    command.Parameters.AddWithValue("@WebOrderNumber", webOrderNumber);
                                    command.CommandTimeout = CommandTimeOut;
                                    command.ExecuteNonQuery();
                                }
                            }
                        }
                        const string updateNonBackOrder = @"update BO set BO.CheckedForBO = 2 from BackOrders as BO  where BO.WebOrderNumber NOT IN ( select WebOrderNumber from #BackOrderRefreshFilter);
                            Drop table #BackOrderRefreshFilter;";

                        using (var command = new SqlCommand(updateNonBackOrder, sqlConnection))
                        {
                            command.CommandTimeout = CommandTimeOut;
                            command.ExecuteNonQuery();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.For((object)this).Info(string.Format("Brasseler: {0} is INVALID in Insite Management Console. Please Check " + ex.ToString(), this), ex);
                throw;
            }
        }
Пример #7
0
        public void SendEmail(SendEmailParameter param)
        {
            var repository = new InfrastructureRepository();

            repository.SendEmail(param);
        }
        public virtual void Execute(DataSet dataSet, CancellationToken cancellationToken)
        {
            CustomerOrder subscriptionOrder = null;

            try
            {
                // Fetching job parameters.
                var jobParameters = this.IntegrationJob.IntegrationJobParameters;
                if (jobParameters == null || jobParameters.Count <= 0)
                {
                    return;
                }

                var subscriptionOrderId = Guid.Empty;

                foreach (var jobParameter in jobParameters)
                {
                    // Check for null or empty for the job parameter value.
                    if (!string.IsNullOrEmpty(jobParameter.Value))
                    {
                        if (jobParameter.JobDefinitionStepParameter.Name.EqualsIgnoreCase("Ship Now"))
                        {
                            shipNow = bool.Parse(jobParameter.Value);
                        }
                        else if (jobParameter.JobDefinitionStepParameter.Name.EqualsIgnoreCase("SmartSupplyOrderId"))
                        {
                            subscriptionOrderId = Guid.Parse(jobParameter.Value);
                        }
                    }

                    // Assigning the job parameter value i.e Customer Order ID in order to pull the customer order.

                }

                // Pull the customer order based on the job parameter value.
                this.UnitOfWork.BeginTransaction();
                subscriptionOrder = this.UnitOfWork.GetRepository<CustomerOrder>().GetTable().FirstOrDefault(x => x.Id == subscriptionOrderId);

                if (subscriptionOrder == null)
                {
                    return;
                }

                // Validate subscription deactivation date before processing next order.
                var subscriptionBrasselerOrder = this.UnitOfWork.GetRepository<SubscriptionBrasseler>().GetTable().Where(x => x.CustomerOrderId == subscriptionOrder.Id).FirstOrDefault();

                if (subscriptionBrasselerOrder != null && subscriptionOrder.Status.EqualsIgnoreCase("SubscriptionOrder"))
                {
                    if (subscriptionBrasselerOrder.DeActivationDate != null)
                    {
                        if (subscriptionBrasselerOrder.DeActivationDate >= DateTimeOffset.Now.Date)
                        {
                            // Retrieve the subscription order to set the SiteContext object and frequency of the subscription order.

                            var userProfile = this.UnitOfWork.GetRepository<UserProfile>().GetTable().FirstOrDefault(x => x.Id == subscriptionOrder.InitiatedByUserProfileId);
                            var billTo = this.UnitOfWork.GetRepository<Customer>().GetTable().FirstOrDefault(x => x.Id == subscriptionOrder.CustomerId);
                            var shipTo = this.UnitOfWork.GetRepository<Customer>().GetTable().FirstOrDefault(x => x.Id == subscriptionOrder.ShipToId);
                            var website = this.UnitOfWork.GetRepository<Website>().GetTable().FirstOrDefault(x => x.Id == subscriptionOrder.WebsiteId);
                            var currency = this.UnitOfWork.GetRepository<Currency>().GetTable().FirstOrDefault(x => x.Id == subscriptionOrder.CurrencyId);

                            // Check for null before setting up the SiteContext object.
                            if (userProfile == null || billTo == null || shipTo == null)
                            {
                                return;
                            }

                            // Set the SiteContext object.
                            SiteContext.SetSiteContext(new SiteContextDto(SiteContext.Current) { UserProfileDto = new UserProfileDto(userProfile), BillTo = billTo, ShipTo = shipTo, WebsiteDto = new WebsiteDto(website), CurrencyDto = new CurrencyDto(currency) });
                            //create new Cart
                            var cart = CreateNewCart(this.UnitOfWork, subscriptionOrder);
                            //Insert in SubscriptionBrasseler
                            if (cart == null)
                            {
                                return;
                            }
                            cart.RecalculatePromotions = true;
                            cart.RecalculateTax = true;
                            this.pricingPipeline.GetCartPricing(new GetCartPricingParameter(cart)
                            {
                                CalculateShipping = true,
                                CalculateTaxes = true,
                                CalculateOrderTotal = true,
                                ForceRecalculation = true,

                            });
                            /*BUSA-755 Smart supply discount issue when user added product qualifies for VDG and smart supply feature*/
                            var newSubscriptionBrasseler = CreateSubscriptionBrasseler(subscriptionBrasselerOrder, cart);
                            if (newSubscriptionBrasseler == null)
                            {
                                return;
                            }
                            // Recalculate the cart to have customer order updated based on Promotion, Tax, Shipping and Handling.
                            //this.pricingPipeline.GetCartPricing(this.UnitOfWork, cart, (OrderLine)null, true);

                            // Build up the update cart paramter.
                            var updateCartParameter = new UpdateCartParameter();
                            updateCartParameter.CartId = cart.Id;

                            if (!string.IsNullOrEmpty(newSubscriptionBrasseler.PaymentMethod))
                            {
                                if (newSubscriptionBrasseler.PaymentMethod.EqualsIgnoreCase("CK"))
                                {
                                    updateCartParameter.IsPaymentProfile = false;
                                    updateCartParameter.TermsCode = "CK";
                                }
                                else
                                {
                                    Guid userPaymentprofileId = Guid.Parse(newSubscriptionBrasseler.PaymentMethod);
                                    var userPaymentprofile = this.UnitOfWork.GetRepository<UserPaymentProfile>().GetTable().Where(x => x.Id == userPaymentprofileId).FirstOrDefault();
                                    if (userPaymentprofile != null)
                                    {
                                        updateCartParameter.PaymentProfileId = userPaymentprofile.CardIdentifier;
                                        updateCartParameter.IsPaymentProfile = true;
                                        updateCartParameter.TermsCode = "CC";
                                    }
                                }
                            }
                            updateCartParameter.Status = "Submitted";
                            updateCartParameter.IsJobQuote = false;
                            updateCartParameter.IsPayPal = false;
                            updateCartParameter.ShipToId = cart.ShipToId;
                            updateCartParameter.ShipViaId = cart.ShipViaId;

                            IHandler<UpdateCartParameter, UpdateCartResult> handler = this.HandlerFactory.GetHandler<IHandler<UpdateCartParameter, UpdateCartResult>>();
                            IUnitOfWork unitOfWork = this.UnitOfWork;
                            var updateCartSubmitResult = handler.Execute(unitOfWork, updateCartParameter, updateCartResult);
                            newSubscriptionBrasseler.NextDelieveryDate = new DateTimeOffset(DateTimeProvider.Current.Now.AddDays(subscriptionBrasselerOrder.Frequency).DateTime, TimeSpan.Zero);
                            this.UnitOfWork.CommitTransaction();
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                LogHelper.For(this).Error(ex);

                if (ex.Message == "Value cannot be null.\r\nParameter name: siteContext")
                {
                    JobLogger.Error("CC Declined");
                    //BUSA-1076 - start: Send Email Notification for SS Failure due to CC decline when triggered from admin console with CC added for sp and ism
                    if (!shipNow)
                    {
                        EmailList orCreateByName_USA = this.UnitOfWork.GetTypedRepository<IEmailListRepository>().GetOrCreateByName("SmartSupplyOrderFailureUSA", "SmartSupplyOrderFailure");
                        EmailList orCreateByName_CA = this.UnitOfWork.GetTypedRepository<IEmailListRepository>().GetOrCreateByName("SmartSupplyOrderFailureCA", "SmartSupplyOrderFailure");
                        EmailList orCreateByName_FR = this.UnitOfWork.GetTypedRepository<IEmailListRepository>().GetOrCreateByName("SmartSupplyOrderFailureFR", "SmartSupplyOrderFailure");
                        dynamic expandoObjects = new ExpandoObject();
                        SendEmailParameter sendEmailParameter = new SendEmailParameter();
                        EmailList emailList_USA = this.UnitOfWork.GetRepository<EmailList>().GetTable().Expand((EmailList x) => x.EmailTemplate).FirstOrDefault((EmailList x) => x.Id == orCreateByName_USA.Id);
                        EmailList emailList_CA = this.UnitOfWork.GetRepository<EmailList>().GetTable().Expand((EmailList x) => x.EmailTemplate).FirstOrDefault((EmailList x) => x.Id == orCreateByName_CA.Id);
                        EmailList emailList_FR = this.UnitOfWork.GetRepository<EmailList>().GetTable().Expand((EmailList x) => x.EmailTemplate).FirstOrDefault((EmailList x) => x.Id == orCreateByName_FR.Id);
                        expandoObjects.OrderNumber = subscriptionOrder.OrderNumber;
                        EmailList emailList = null;
                        expandoObjects.CustomerNumber = subscriptionOrder.CustomerNumber;
                        if (subscriptionOrder != null && !string.IsNullOrEmpty(subscriptionOrder.ShipTo.CustomerSequence))
                        {
                            expandoObjects.CustomerShipToNumber = subscriptionOrder.ShipTo.CustomerSequence;
                        }
                        else
                        {
                            expandoObjects.CustomerShipToNumber = string.Empty;
                        }

                        var languageid = this.UnitOfWork.GetRepository<CustomProperty>().GetTable().Where(x => x.ParentTable == "UserProfile" && x.Name == "userLanguage" && x.ParentId == updateCartResult.GetCartResult.Cart.InitiatedByUserProfileId).FirstOrDefault()?.Value;
                        var languageName = this.UnitOfWork.GetRepository<Language>().GetTable().Where(x => x.Id.ToString() == languageid).FirstOrDefault()?.LanguageCode;

                        string htmlTemplate = string.Empty;
                        if (updateCartResult.GetCartResult.Cart.OrderNumber.StartsWith("W") || languageName == "en-us")
                        {
                            htmlTemplate = GetHtmlTemplate(emailList_USA);
                            emailList = emailList_USA;

                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(languageid) && languageName=="fr-CA")
                            {
                                htmlTemplate = GetHtmlTemplate(emailList_FR);
                                emailList = emailList_FR;

                            }
                            else
                            {
                                htmlTemplate = GetHtmlTemplate(emailList_CA);
                                emailList = emailList_CA;
                            }

                        }
                        sendEmailParameter.Body = this.EmailService.Value.ParseTemplate(htmlTemplate, expandoObjects);
                        sendEmailParameter.Subject = emailList.Subject;
                        sendEmailParameter.ToAddresses.Add(updateCartResult.GetCartResult.Cart.CreatedBy);
                        var emailCCAddresses = this.UnitOfWork.GetRepository<Salesperson>().GetTable().Where(x => x.Id == updateCartResult.GetCartResult.Cart.SalespersonId).FirstOrDefault();
                        var customProperty = this.UnitOfWork.GetRepository<CustomProperty>().GetTable().Where(x => x.ParentId == updateCartResult.GetCartResult.Cart.ShipToId);

                        foreach (var iAmCodeEmail in customProperty)
                        {
                            if (iAmCodeEmail.Name == "IAMCodeEmail")
                            {
                                var insideRepEmail = iAmCodeEmail.Value;

                                if (!string.IsNullOrEmpty(insideRepEmail))
                                {
                                    sendEmailParameter.CCAddresses.Add(insideRepEmail);
                                }
                            }
                        }
                        if ((emailCCAddresses != null) && (!string.IsNullOrEmpty(emailCCAddresses.Email)))
                        {
                            sendEmailParameter.CCAddresses.Add(emailCCAddresses.Email);
                        }

                        string defaultEmailAddress = this.CustomSettings.DefaultEmailAddress;
                        sendEmailParameter.FromAddress = (emailList.FromAddress.IsBlank() ? defaultEmailAddress : emailList.FromAddress);
                        sendEmailParameter.ReplyToAddresses = new List<string>();
                        sendEmailParameter.ExtendedProperties = new NameValueCollection();
                        this.EmailService.Value.SendEmail(sendEmailParameter, this.UnitOfWork);

                    }
                    //BUSA-1076 - end:Send Email Notification for SS Failure due to CC decline when triggered from admin console with CC added  for sp and ism
                }

                throw;
            }
            finally
            {
                if (subscriptionOrder != null)
                {
                    var subscriptionBrasselerOrder = this.UnitOfWork.GetRepository<SubscriptionBrasseler>().GetTable().Where(x => x.CustomerOrderId == subscriptionOrder.Id).FirstOrDefault();
                    if (subscriptionBrasselerOrder.DeActivationDate != null)
                    {
                        if (subscriptionBrasselerOrder.DeActivationDate >= DateTimeOffset.Now.Date)
                        {
                            // Added ship now condition to not update the next delievery date if it is true. Order needs to be placed now. By default value is false.
                            if (subscriptionBrasselerOrder != null)
                            {
                                subscriptionBrasselerOrder.NextDelieveryDate = new DateTimeOffset(DateTimeProvider.Current.Now.AddDays(subscriptionBrasselerOrder.Frequency).DateTime, TimeSpan.Zero);
                            }
                            this.UnitOfWork.Save();
                        }
                    }
                }
            }
        }
Пример #9
0
        public override UpdateCartResult Execute(IUnitOfWork unitOfWork, UpdateCartParameter parameter, UpdateCartResult result)
        {
            if (!parameter.Status.EqualsIgnoreCase("AwaitingApproval"))
            {
                return(this.NextHandler.Execute(unitOfWork, parameter, result));
            }
            CustomerOrder cart = result.GetCartResult.Cart;

            try
            {
                if (parameter.Status.EqualsIgnoreCase("AwaitingApproval") && result.GetCartResult.Cart != null)
                {
                    CustomerOrder  order         = result.GetCartResult.Cart;
                    string         approverEmail = string.IsNullOrEmpty(order.ApproverUserProfile.Email) ? "" : order.ApproverUserProfile.Email;
                    UserProfileDto userProfile   = SiteContext.Current.UserProfileDto;
                    dynamic        emailModel    = new ExpandoObject();
                    emailModel.OrderNumber = order.OrderNumber;
                    emailModel.Name        = order.PlacedByUserName;
                    emailModel.Approver    = order.ApproverUserProfile.FirstName;
                    emailModel.Reason      = order.ApproverMessage;
                    emailModel.totalCost   = order.ShippingCharges;
                    DateTime date = order.OrderDate.Date;
                    emailModel.OrderDate  = date.ToShortDateString();
                    emailModel.CustomerPO = order.CustomerPO;
                    emailModel.OrderLines = new List <ExpandoObject>();
                    foreach (OrderLine orderLine in order.OrderLines)
                    {
                        dynamic expandoObjects = new ExpandoObject();
                        expandoObjects.ProductNumber        = orderLine.Product.ErpNumber;
                        expandoObjects.Description          = orderLine.Description;
                        expandoObjects.QtyOrdered           = decimal.Round(orderLine.QtyOrdered, 2);
                        expandoObjects.QtyOrderedDisplay    = expandoObjects.QtyOrdered.ToString("0.##");
                        expandoObjects.UnitNetPrice         = orderLine.UnitNetPrice;
                        expandoObjects.UnitNetPriceDisplay  = this.CurrencyFormatProvider.GetString(orderLine.UnitNetPrice, order.Currency);
                        expandoObjects.ExtendedUnitNetPrice = this.OrderLineUtilities.GetTotalNetPrice(orderLine);
                        dynamic currency = expandoObjects;
                        ICurrencyFormatProvider currencyFormatProvider = this.CurrencyFormatProvider;
                        currency.ExtendedUnitNetPriceDisplay = currencyFormatProvider.GetString(expandoObjects.ExtendedUnitNetPrice, order.Currency);
                        emailModel.OrderLines.Add(expandoObjects);
                    }
                    emailModel.Shipping       = result.GetCartResult.ShippingAndHandling;
                    emailModel.SubTotal       = result.GetCartResult.OrderSubTotal;
                    emailModel.Tax            = result.GetCartResult.TotalTax;
                    emailModel.OrderTotal     = result.GetCartResult.OrderGrandTotal;
                    emailModel.CustomerNumber = order.CustomerNumber;
                    emailModel.BTCompanyName  = order.BTCompanyName;
                    emailModel.BTAddress1     = order.BTAddress1;
                    emailModel.BTAddress2     = order.BTAddress2;
                    emailModel.BTAddress3     = order.BTAddress3;
                    emailModel.BTCity         = order.BTCity;
                    emailModel.BTState        = order.BTState;
                    emailModel.BTPostalCode   = order.BTPostalCode;
                    emailModel.STCompanyName  = order.STCompanyName;
                    emailModel.STAddress1     = order.STAddress1;
                    emailModel.STAddress2     = order.STAddress2;
                    emailModel.STAddress3     = order.STAddress3;
                    emailModel.STCity         = order.STCity;
                    emailModel.STState        = order.STState;
                    emailModel.STPostalCode   = order.STPostalCode;
                    emailModel.BTDisplayName  = order.BTFirstName + " " + order.BTLastName;
                    emailModel.STDisplayName  = order.STFirstName + " " + order.STLastName;
                    emailModel.BTFirstName    = order.BTFirstName;
                    emailModel.BTLastName     = order.BTLastName;
                    emailModel.STFirstName    = order.STFirstName;
                    emailModel.STLastName     = order.STLastName;
                    if (order.ShipVia != null && order.ShipVia.Carrier != null)
                    {
                        emailModel.ShipMethod = order.ShipVia.Description;
                    }
                    else
                    {
                        emailModel.ShipMethod = string.Empty;
                    }
                    emailModel.Notes                  = order.Notes;
                    emailModel.Handling               = order.HandlingCharges;
                    emailModel.HandlingDisplay        = this.CurrencyFormatProvider.GetString(order.HandlingCharges, order.Currency);
                    emailModel.OrderSubTotalDisplay   = this.CurrencyFormatProvider.GetString(result.GetCartResult.OrderSubTotal, order.Currency);
                    emailModel.OrderGrandTotalDisplay = this.CurrencyFormatProvider.GetString(result.GetCartResult.OrderGrandTotal, order.Currency);
                    emailModel.OrderTotalDueDisplay   = this.CurrencyFormatProvider.GetString(result.GetCartResult.OrderGrandTotal, order.Currency);
                    emailModel.CustomerOrderTaxes     = new List <ExpandoObject>();
                    foreach (CustomerOrderTax customerOrderTax in
                             from o in order.CustomerOrderTaxes
                             orderby o.SortOrder
                             select o)
                    {
                        dynamic expandoObjects = new ExpandoObject();
                        expandoObjects.TaxCode          = this.TranslationLocalizer.Value.TranslateLabel(customerOrderTax.TaxCode);
                        expandoObjects.TaxDescription   = this.TranslationLocalizer.Value.TranslateLabel(customerOrderTax.TaxDescription);
                        expandoObjects.TaxRate          = customerOrderTax.TaxRate;
                        expandoObjects.TaxAmount        = customerOrderTax.TaxAmount;
                        expandoObjects.TaxAmountDisplay = this.CurrencyFormatProvider.GetString(customerOrderTax.TaxAmount, order.Currency);
                        expandoObjects.SortOrder        = customerOrderTax.SortOrder;
                        emailModel.CustomerOrderTaxes.Add(expandoObjects);
                    }
                    emailModel.CreditCardWillBeCharged = result.GetCartResult.OrderGrandTotal;
                    emailModel.TotalTaxDisplay         = this.CurrencyFormatProvider.GetString(result.GetCartResult.TotalTax, order.Currency);

                    var promotionProductDiscountTotal = this.CustomerOrderUtilities.Value.GetPromotionProductDiscountTotal(order);
                    emailModel.PromotionProductDiscountTotal        = promotionProductDiscountTotal;
                    emailModel.PromotionProductDiscountTotalDisplay = this.CurrencyFormatProvider.GetString(promotionProductDiscountTotal, order.Currency);

                    var promotionOrderDiscountTotal = this.CustomerOrderUtilities.Value.GetPromotionOrderDiscountTotal(order);
                    emailModel.PromotionOrderDiscountTotal        = promotionOrderDiscountTotal;
                    emailModel.PromotionOrderDiscountTotalDisplay = this.CurrencyFormatProvider.GetString(promotionOrderDiscountTotal, order.Currency);

                    var promotionShippingDiscountTotal = this.CustomerOrderUtilities.Value.GetPromotionShippingDiscountTotal(order);
                    emailModel.PromotionShippingDiscountTotal        = promotionShippingDiscountTotal;
                    emailModel.PromotionShippingDiscountTotalDisplay = this.CurrencyFormatProvider.GetString(promotionShippingDiscountTotal, order.Currency);

                    var giftCardTotal = this.CustomerOrderUtilities.Value.GetGiftCardTotal(order);
                    emailModel.GiftCardTotal        = giftCardTotal;
                    emailModel.GiftCardTotalDisplay = this.CurrencyFormatProvider.GetString(giftCardTotal, order.Currency);
                    //changes for BUSA-401 starts
                    //emailModel.WebsiteUrl = order.Website.DomainName;
                    //changes for BUSA-401 ends

                    emailModel.WebsiteUrl = HttpContext.Current.Request.ActualUrl().GetLeftPart(UriPartial.Authority);//BUSA-552 : Incorrect URL in Order Approve email template

                    var emailList = this.GetOrCreateEmailList("OrderApprove", "You have a new order to approve");
                    //this.EmailService.SendEmailList(emailList.Id, approverEmail, emailModel, string.Format("{0} {1}", emailList.Subject, order.OrderNumber), this.UnitOfWork);
                    //BUSA-489 - commented the above line and added the below block

                    //BUSA - 489 - start
                    emailList = unitOfWork.GetRepository <EmailList>().GetTable().Expand((EmailList x) => x.EmailTemplate).FirstOrDefault((EmailList x) => x.Id == emailList.Id);
                    if (emailList != null)
                    {
                        SendEmailParameter sendEmailParameter = new SendEmailParameter();
                        string             htmlTemplate       = GetHtmlTemplate(emailList);
                        sendEmailParameter.Body = this.EmailService.ParseTemplate(htmlTemplate, emailModel);

                        sendEmailParameter.Subject = string.Format("{0} {1}", emailList.Subject, order.OrderNumber);
                        sendEmailParameter.ToAddresses.Add(approverEmail);
                        sendEmailParameter.BccAddresses = new List <string>();

                        var emailCCAddresses = customSettings.EmailCCAddresses;
                        if (!string.IsNullOrEmpty(emailCCAddresses))
                        {
                            sendEmailParameter.CCAddresses.Add(emailCCAddresses);
                        }
                        string defaultEmailAddress = customSettings.DefaultEmailAddress;
                        sendEmailParameter.FromAddress = (emailList.FromAddress.IsBlank() ? defaultEmailAddress : emailList.FromAddress);
                        //Start BUSA - 685 :Create an ability to resend an email for Order Approve
                        var emailCCAddressOfFrom    = userProfile.Email;
                        var emailCCAddressOfSupport = sendEmailParameter.FromAddress;
                        if (!string.IsNullOrEmpty(emailCCAddressOfFrom))
                        {
                            sendEmailParameter.CCAddresses.Add(emailCCAddressOfFrom);
                        }
                        if (!string.IsNullOrEmpty(emailCCAddressOfSupport))
                        {
                            sendEmailParameter.CCAddresses.Add(emailCCAddressOfSupport);
                        }
                        //Start BUSA - 685 :Create an ability to resend an email for Order Approve
                        sendEmailParameter.ReplyToAddresses   = new List <string>();
                        sendEmailParameter.ExtendedProperties = new NameValueCollection();
                        SendEmail(sendEmailParameter, unitOfWork);
                    }
                    //BUSA - 489 - end
                }
            }
            catch (Exception ex)
            {
                LogHelper.For((object)this).Error((object)("There was a problem executing UpdateCartResult" + (object)ex.InnerException), ex.InnerException, (string)null, (object)null);
                throw ex;
            }
            return(NextHandler.Execute(unitOfWork, parameter, result));
        }
Пример #10
0
        public void SendEmail(SendEmailParameter parameter, IUnitOfWork unitOfWork)
        {
            foreach (string toAddress in (IEnumerable <string>)parameter.ToAddresses)
            {
                if (!RegularExpressionLibrary.IsValidEmail(toAddress))
                {
                    throw new ArgumentException("The value '{email}' in the ToAddresses collection is not a valid email address".FormatWith((object)new
                    {
                        email = toAddress
                    }, (IFormatProvider)null));
                }
            }
            if (!RegularExpressionLibrary.IsValidEmail(parameter.FromAddress))
            {
                throw new ArgumentException("The value '{email}' for the FromAddress is not a valid email address".FormatWith((object)new
                {
                    email = parameter.FromAddress
                }, (IFormatProvider)null));
            }
            foreach (string replyToAddress in (IEnumerable <string>)parameter.ReplyToAddresses)
            {
                if (!RegularExpressionLibrary.IsValidEmail(replyToAddress))
                {
                    throw new ArgumentException("The value '{email}' in the ReplyToAddresses collection is not a valid email address".FormatWith((object)new
                    {
                        email = replyToAddress
                    }, (IFormatProvider)null));
                }
            }
            foreach (string ccAddress in (IEnumerable <string>)parameter.CCAddresses)
            {
                if (!RegularExpressionLibrary.IsValidEmail(ccAddress))
                {
                    throw new ArgumentException("The value '{email}' in the CCAddresses collection is not a valid email address".FormatWith((object)new
                    {
                        email = ccAddress
                    }, (IFormatProvider)null));
                }
            }
            foreach (string bccAddress in (IEnumerable <string>)parameter.BccAddresses)
            {
                if (!RegularExpressionLibrary.IsValidEmail(bccAddress))
                {
                    throw new ArgumentException("The value '{email}' in the BccAddresses collection is not a valid email address".FormatWith((object)new
                    {
                        email = bccAddress
                    }, (IFormatProvider)null));
                }
            }
            IRepository <EmailMessage> repository = unitOfWork.GetRepository <EmailMessage>();
            EmailMessage emailMessage             = repository.Create();

            emailMessage.Body    = parameter.Body;
            emailMessage.Subject = parameter.Subject;
            repository.Insert(emailMessage);
            foreach (string toAddress in (IEnumerable <string>)parameter.ToAddresses)
            {
                emailMessage.EmailMessageAddresses.Add(new EmailMessageAddress()
                {
                    EmailAddress = toAddress,
                    Type         = EmailMessageAddressType.To.ToString()
                });
            }
            emailMessage.EmailMessageAddresses.Add(new EmailMessageAddress()
            {
                EmailAddress = parameter.FromAddress,
                Type         = EmailMessageAddressType.From.ToString()
            });
            foreach (string ccAddress in (IEnumerable <string>)parameter.CCAddresses)
            {
                emailMessage.EmailMessageAddresses.Add(new EmailMessageAddress()
                {
                    EmailAddress = ccAddress,
                    Type         = EmailMessageAddressType.CC.ToString()
                });
            }
            foreach (string bccAddress in (IEnumerable <string>)parameter.BccAddresses)
            {
                emailMessage.EmailMessageAddresses.Add(new EmailMessageAddress()
                {
                    EmailAddress = bccAddress,
                    Type         = EmailMessageAddressType.BCC.ToString()
                });
            }
            foreach (string replyToAddress in (IEnumerable <string>)parameter.ReplyToAddresses)
            {
                emailMessage.EmailMessageAddresses.Add(new EmailMessageAddress()
                {
                    EmailAddress = replyToAddress,
                    Type         = EmailMessageAddressType.ReplyTo.ToString()
                });
            }
            EmailMessageDeliveryAttempt emailMessageDeliveryAttempt = new EmailMessageDeliveryAttempt();

            emailMessage.EmailMessageDeliveryAttempts.Add(emailMessageDeliveryAttempt);
            unitOfWork.Save();
            string emailTestAddress = EmailsSettings.TestEmail;

            Task.Factory.StartNew((Action)(() => this.DoActualSend(emailMessage, emailMessageDeliveryAttempt, emailTestAddress)));
        }
        public override UpdateCartResult Execute(IUnitOfWork unitOfWork, UpdateCartParameter parameter, UpdateCartResult result)
        {
            if (!parameter.Status.EqualsIgnoreCase("Submitted"))
            {
                return(this.NextHandler.Execute(unitOfWork, parameter, result));
            }

            //BUSA- 463 Subscription : Send Auto SmartSupply Order Email - starts
            // CustomerOrder customerOrder= result.GetCartResult.Cart.
            var isExistingOrder = unitOfWork.GetRepository <SubscriptionBrasseler>().GetTable().Where(x => x.CustomerOrderId == result.GetCartResult.Cart.Id).Count();

            this.PopulateOrderEmailModel(result.ConfirmationEmailModel, result.GetCartResult.Cart, unitOfWork);
            EmailList orCreateByName = null;

            if (isExistingOrder > 0)
            {
                orCreateByName = unitOfWork.GetTypedRepository <IEmailListRepository>().GetOrCreateByName("SmartSupplyOrderPlaced", "SmartSupply Order Confirmation");
            }
            else
            {
                orCreateByName = unitOfWork.GetTypedRepository <IEmailListRepository>().GetOrCreateByName("OrderConfirmation", "Brasseler Order Confirmation");
            }
            //BUSA- 463 Subscription : Send Auto SmartSupply Order Email -ends

            //List<string> list = this.BuildEmailValues.Value.BuildOrderEmailToList(customerOrder.Id).Split(new char[] { ',' }).ToList<string>();

            //BUSA 590 : W04593 -Single Order confirmation email is triggered to customer and inside sales rep.
            List <string> list = BuildEmailValuesWithoutSalesRep(result.GetCartResult.Cart.Id, unitOfWork).Split(new char[] { ',' }).ToList <string>();

            //BUSA - 829 : Email To Approver On approval
            //string ApproverEmailId = customerOrder.ModifiedBy;
            string userName      = result.GetCartResult.Cart.ModifiedBy;
            var    userProfile   = unitOfWork.GetRepository <UserProfile>().GetTable().Where(x => x.UserName == userName);
            string approverEmail = string.Empty;

            if (userProfile != null)
            {
                approverEmail = userProfile.FirstOrDefault().Email;
                list.Add(approverEmail);
            }
            //BUSA - 829 : Email To Approver On approval

            //BUSA - 489 - start
            EmailList emailList = unitOfWork.GetRepository <EmailList>().GetTable().Expand((EmailList x) => x.EmailTemplate).FirstOrDefault((EmailList x) => x.Id == orCreateByName.Id);

            if (emailList != null)
            {
                SendEmailParameter sendEmailParameter = new SendEmailParameter();
                string             htmlTemplate       = GetHtmlTemplate(emailList);
                sendEmailParameter.Body = this.EmailService.Value.ParseTemplate(htmlTemplate, result.ConfirmationEmailModel);

                sendEmailParameter.Subject      = emailList.Subject;
                sendEmailParameter.ToAddresses  = list;
                sendEmailParameter.BccAddresses = new List <string>();

                var emailCCAddresses = customSettings.EmailCCAddresses;
                if (!string.IsNullOrEmpty(emailCCAddresses))
                {
                    sendEmailParameter.CCAddresses.Add(emailCCAddresses);
                }

                string defaultEmailAddress = customSettings.DefaultEmailAddress;
                sendEmailParameter.FromAddress        = (emailList.FromAddress.IsBlank() ? defaultEmailAddress : emailList.FromAddress);
                sendEmailParameter.ReplyToAddresses   = new List <string>();
                sendEmailParameter.ExtendedProperties = new NameValueCollection();
                this.EmailService.Value.SendEmail(sendEmailParameter, unitOfWork);
                //BUSA-253 start : Sales Rep Notification
                SendOrderConfirmationToSalesRep(unitOfWork, result.GetCartResult.Cart, result.ConfirmationEmailModel);
                //BUSA-253 end : Sales Rep Notification
            }
            string applyCreditCard       = "No";
            var    newuserCustomerNumber = customSettings.Brasseler_GuestCustomerNumber;
            var    companyNameIdentifier = customSettings.CompanyNameIdentifier;
            bool   isNewUser             = (SiteContext.Current.UserProfileDto != null && !SiteContext.Current.UserProfileDto.IsGuest && SiteContext.Current.BillTo.CustomerNumber.EqualsIgnoreCase(companyNameIdentifier + newuserCustomerNumber));

            if (parameter.Status.EqualsIgnoreCase("Submitted") && result.ResultCode.Equals(ResultCode.Success) && isNewUser)
            {
                //BUSA-234 -Start
                CustomerOrder customerOrder = result.GetCartResult.Cart;
                if (customerOrder != null && customerOrder.CreditCardTransactions != null && customerOrder.CreditCardTransactions.Count > 0)
                {
                    ICollection <CreditCardTransaction> creditCardTransaction = customerOrder.CreditCardTransactions;
                    if (creditCardTransaction != null && creditCardTransaction.Count > 0)
                    {
                        foreach (CreditCardTransaction creditCard in creditCardTransaction)
                        {
                            if (!string.IsNullOrEmpty(creditCard.PNRef))
                            {
                                applyCreditCard = "Yes";
                            }
                        }
                    }
                }
                // BUSA - 234 - end

                dynamic emailModel = PopulateUserInfoData(applyCreditCard, unitOfWork);
                emailModel.OrderNumber = customerOrder.OrderNumber;
                //emailModel.OrderNumber = result.GetCartResult.Cart.OrderNumber;
                var emailTo    = customSettings.NewCustomerInfoEmailTo;
                var emailList1 = unitOfWork.GetTypedRepository <IEmailListRepository>().GetOrCreateByName("NewUserInformation", "New User Information");
                if (emailTo != null && !string.IsNullOrEmpty(emailTo))
                {
                    EmailService.Value.SendEmailList(emailList1.Id, emailTo, emailModel, "New User Information", unitOfWork);
                }
            }
            return(this.NextHandler.Execute(unitOfWork, parameter, result));
        }
        //BUSA-253 start : Sales Rep Notification
        //****************************************************8
        protected void SendOrderConfirmationToSalesRep(IUnitOfWork unitOfWork, CustomerOrder customerOrder, ExpandoObject expandoObjects)
        {
            //BUSA - 623 start : Add Inside Rep to Customer Custom properties tab
            string emailCCAddresses = string.Empty;
            //BUSA - 623 end : Add Inside Rep to Customer Custom properties tab
            List <string> lstToAddress = new List <string>();

            string email = string.Empty;

            //BUSA-590 start : W04593 -Single Order confirmation email is triggered to customer and inside sales rep
            if (!string.IsNullOrEmpty(customerOrder.ShipTo.CustomerSequence))
            {
                var shipToSalesRep = customerOrder.ShipTo.PrimarySalespersonId;
                if (shipToSalesRep != null)
                {
                    email = unitOfWork.GetRepository <Salesperson>().GetTable().Where(x => x.Id == shipToSalesRep).FirstOrDefault().Email.ToString();
                    //BUSA - 623 start : Add Inside Rep to Customer Custom properties tab
                    if (string.IsNullOrEmpty(email))
                    {
                        GetInsideSalesRep(unitOfWork, customerOrder, customerOrder.ShipToId);
                        email = insideRepEmail;
                    }
                }
                else
                {
                    GetInsideSalesRep(unitOfWork, customerOrder, customerOrder.ShipToId);
                    email = insideRepEmail;
                }
                //BUSA - 623 end : Add Inside Rep to Customer Custom properties tab
            }
            else
            {
                if (customerOrder.SalespersonId != null)
                {
                    email = unitOfWork.GetRepository <Salesperson>().GetTable().Where(x => x.Id == customerOrder.SalespersonId).FirstOrDefault().Email.ToString();
                    //BUSA - 623 start : Add Inside Rep to Customer Custom properties tab
                    if (string.IsNullOrEmpty(email))
                    {
                        GetInsideSalesRep(unitOfWork, customerOrder, customerOrder.CustomerId);
                        email = insideRepEmail;
                    }
                }
                else
                {
                    GetInsideSalesRep(unitOfWork, customerOrder, customerOrder.CustomerId);
                    email = insideRepEmail;
                }
                //BUSA - 623 end : Add Inside Rep to Customer Custom properties tab
            }
            //BUSA-590 end : W04593 -Single Order confirmation email is triggered to customer and inside sales rep



            if (!string.IsNullOrEmpty(email))
            {
                this.PopulateOrderEmailModel(expandoObjects, customerOrder, unitOfWork);
                //BUSA - 832 : Subject changed to 'Brasseler Order Confirmation'
                EmailList orCreateByName = unitOfWork.GetTypedRepository <IEmailListRepository>().GetOrCreateByName("SalesOrderConfirmation", "Brasseler Order Confirmation");
                lstToAddress.Add(email);
                EmailList emailList = unitOfWork.GetRepository <EmailList>().GetTable().Expand((EmailList x) => x.EmailTemplate).FirstOrDefault((EmailList x) => x.Id == orCreateByName.Id);
                if (emailList != null)
                {
                    SendEmailParameter sendEmailParameter = new SendEmailParameter();
                    string             htmlTemplate       = GetHtmlTemplate(emailList);
                    sendEmailParameter.Body = this.EmailService.Value.ParseTemplate(htmlTemplate, expandoObjects);

                    sendEmailParameter.Subject      = emailList.Subject;
                    sendEmailParameter.ToAddresses  = lstToAddress;
                    sendEmailParameter.BccAddresses = new List <string>();

                    //BUSA - 623 start : Add Inside Rep to Customer Custom properties tab
                    if (!string.IsNullOrEmpty(customerOrder.ShipTo.CustomerSequence))
                    {
                        GetInsideSalesRep(unitOfWork, customerOrder, customerOrder.ShipToId);
                    }
                    else
                    {
                        GetInsideSalesRep(unitOfWork, customerOrder, customerOrder.CustomerId);
                    }

                    emailCCAddresses = insideRepEmail;
                    if (email == emailCCAddresses)
                    {
                        emailCCAddresses = null;
                    }
                    //BUSA - 623 end : Add Inside Rep to Customer Custom properties tab

                    if (!string.IsNullOrEmpty(emailCCAddresses))
                    {
                        sendEmailParameter.CCAddresses.Add(emailCCAddresses);
                    }

                    string defaultEmailAddress = customSettings.DefaultEmailAddress;
                    sendEmailParameter.FromAddress        = (emailList.FromAddress.IsBlank() ? defaultEmailAddress : emailList.FromAddress);
                    sendEmailParameter.ReplyToAddresses   = new List <string>();
                    sendEmailParameter.ExtendedProperties = new NameValueCollection();
                    this.EmailService.Value.SendEmail(sendEmailParameter, unitOfWork);
                }
            }
        }
        public override void SendEmailList(Guid emailListId, IList <string> toAddresses, ExpandoObject templateModel, string subject, IUnitOfWork unitOfWork, Guid?templateWebsiteId = null, IList <Attachment> attachments = null)
        {
            object        SenderName;
            List <String> Sender = new List <String>();

            foreach (string toAddress in toAddresses)
            {
                if (RegularExpressionLibrary.IsValidEmail(toAddress))
                {
                    continue;
                }
                throw new ArgumentException(string.Concat("To address: ", toAddress, " is not a valid email address."));
            }
            EmailList emailList = this.GetEmailList(unitOfWork, emailListId, templateWebsiteId);

            if (emailList == null)
            {
                return;
            }
            //BUSA-1090 Wish list email notification (share)
            if (((IDictionary <String, Object>)templateModel).TryGetValue("SenderName", out SenderName))
            {
                ((IDictionary <String, Object>)templateModel).TryGetValue("SenderName", out SenderName);
                Sender.Add(SenderName.ToString());
                foreach (string CCAddress in Sender)
                {
                    if (RegularExpressionLibrary.IsValidEmail(CCAddress))
                    {
                        continue;
                    }
                    throw new ArgumentException(string.Concat("CC address: ", CCAddress, " is not a valid email address."));
                }
            }

            //BUSA-1090 Wish list email notification (share)
            emailList.FromAddress = CustomSettings.DefaultWishListEmailAddress;

            // add toAddresses and ccAddresses for RMA notification
            object        IsRmaEmail;
            List <string> ccAddresses = new List <string>();

            if (((IDictionary <String, Object>)templateModel).TryGetValue("IsRmaEmail", out IsRmaEmail))
            {
                if (!string.IsNullOrEmpty(CustomSettings.RMA_ToAddress))
                {
                    string[] addresses = CustomSettings.RMA_ToAddress.Split(';');
                    for (int i = 0; i < addresses.Length; i++)
                    {
                        toAddresses.Add(addresses[i].Trim());
                    }
                }
                if (!string.IsNullOrEmpty(CustomSettings.RMA_CC_Address))
                {
                    string[] addresses = CustomSettings.RMA_CC_Address.Split(';');
                    for (int i = 0; i < addresses.Length; i++)
                    {
                        ccAddresses.Add(addresses[i].Trim());
                    }
                }
                if (!string.IsNullOrEmpty(CustomSettings.RMA_BCC_Address))
                {
                    string[] addresses = CustomSettings.RMA_BCC_Address.Split(';');
                    for (int i = 0; i < addresses.Length; i++)
                    {
                        Sender.Add(addresses[i].Trim());
                    }
                }
            }

            SendEmailParameter sendEmailParameter = new SendEmailParameter()
            {
                ToAddresses  = toAddresses,
                CCAddresses  = ccAddresses,
                Attachments  = attachments,
                BccAddresses = Sender,
                FromAddress  = (emailList.FromAddress.IsBlank() ? this.EmailsSettings.DefaultEmail : emailList.FromAddress),
                Subject      = (subject.IsBlank() ? this.EntityTranslationService.TranslateProperty <EmailList>(emailList, (EmailList o) => o.Subject) : subject)
            };

            SendEmailParameter sendEmailParameter1 = sendEmailParameter;
            string             htmlTemplate        = this.GetHtmlTemplate(emailList, templateWebsiteId);

            this.ParseAndSendEmail(htmlTemplate, templateModel, sendEmailParameter1, unitOfWork);
        }