Exemple #1
0
        public async Task <string> SendEmailNotification(int CustomerID, int OrderID, IConfiguration _configuration)
        {
            string status = string.Empty;

            try
            {
                ConfigDataAccess _configAccess = new ConfigDataAccess(_configuration);

                BuddyDataAccess _buddyAccess = new BuddyDataAccess();

                CommonDataAccess _commonAccess = new CommonDataAccess(_configuration);

                DatabaseResponse templateResponse = await _configAccess.GetEmailNotificationTemplate(NotificationEvent.OrderSuccess.ToString());

                LogInfo.Information("Email Customer : " + CustomerID);

                // Get Customer Data from CustomerID for email and Name
                CustomerDetails customer = await _commonAccess.GetCustomerDetailByOrder(CustomerID, OrderID);

                LogInfo.Information("Email Customer data : " + JsonConvert.SerializeObject(customer));

                if (customer != null && !string.IsNullOrEmpty(customer.DeliveryEmail))
                {
                    StringBuilder orderedNumbersSb = new StringBuilder();

                    StringBuilder deliveryAddressSb = new StringBuilder();

                    orderedNumbersSb.Append("<table width='100%'>");

                    int counter = 0;

                    foreach (OrderNumber number in customer.OrderedNumbers)
                    {
                        if (counter > 0)
                        {
                            orderedNumbersSb.Append("<tr><td width='100%' colspan='3'> </td></tr>");
                        }
                        orderedNumbersSb.Append("<tr><td width='25%'>MobileNumber :<td width='20%'>");
                        orderedNumbersSb.Append(number.MobileNumber);
                        orderedNumbersSb.Append("</td><td width ='55%'></td></tr>");
                        orderedNumbersSb.Append("<tr><td width='25%'>Plan :<td width='20%'>");
                        orderedNumbersSb.Append(number.PlanMarketingName);
                        orderedNumbersSb.Append("</td><td width ='55%'>");
                        orderedNumbersSb.Append(number.PricingDescription);
                        orderedNumbersSb.Append("</td></tr> ");
                        counter++;
                    }

                    orderedNumbersSb.Append("</table>");

                    if (!string.IsNullOrEmpty(customer.ShippingBuildingNumber))
                    {
                        deliveryAddressSb.Append(customer.ShippingBuildingNumber);
                    }

                    if (!string.IsNullOrEmpty(customer.ShippingStreetName))
                    {
                        if (deliveryAddressSb.ToString() != "")
                        {
                            deliveryAddressSb.Append(" ");
                        }

                        deliveryAddressSb.Append(customer.ShippingStreetName);
                    }

                    deliveryAddressSb.Append("<br />");

                    StringBuilder shippingAddr2 = new StringBuilder();

                    if (!string.IsNullOrEmpty(customer.ShippingFloor))
                    {
                        shippingAddr2.Append(customer.ShippingFloor);
                    }

                    if (!string.IsNullOrEmpty(customer.ShippingUnit))
                    {
                        if (shippingAddr2.ToString() != "")
                        {
                            shippingAddr2.Append(" ");
                        }
                        shippingAddr2.Append(customer.ShippingUnit);
                    }

                    if (!string.IsNullOrEmpty(customer.ShippingBuildingName))
                    {
                        if (shippingAddr2.ToString() != "")
                        {
                            shippingAddr2.Append(" ");
                        }

                        shippingAddr2.Append(customer.ShippingBuildingName);
                    }

                    deliveryAddressSb.Append(shippingAddr2.ToString());

                    deliveryAddressSb.Append("<br />");

                    if (!string.IsNullOrEmpty(customer.ShippingPostCode))
                    {
                        deliveryAddressSb.Append(customer.ShippingPostCode);
                    }

                    string deliveryDate = customer.SlotDate.ToString("dd MMM yyyy") + " " + new DateTime(customer.SlotFromTime.Ticks).ToString("hh:mm tt")
                                          + " to " + new DateTime(customer.SlotToTime.Ticks).ToString("hh:mm tt");

                    var notificationMessage = MessageHelper.GetMessage(customer.ToEmailList, customer.Name,

                                                                       NotificationEvent.OrderSuccess.ToString(),

                                                                       ((EmailTemplate)templateResponse.Results).TemplateName, _configuration, customer.DeliveryEmail,
                                                                       customer.OrderNumber, orderedNumbersSb.ToString(), deliveryAddressSb.ToString(),
                                                                       customer.AlternateRecipientName == null ? customer.Name : customer.AlternateRecipientName,
                                                                       customer.AlternateRecipientContact == null ? customer.ShippingContactNumber : customer.AlternateRecipientContact,
                                                                       string.IsNullOrEmpty(customer.AlternateRecipientEmail) ? customer.DeliveryEmail : customer.AlternateRecipientEmail,
                                                                       deliveryDate, customer.ReferralCode);

                    DatabaseResponse notificationResponse = await _configAccess.GetConfiguration(ConfiType.Notification.ToString());

                    MiscHelper parser = new MiscHelper();

                    var notificationConfig = parser.GetNotificationConfig((List <Dictionary <string, string> >)notificationResponse.Results);

                    LogInfo.Information("Email Message to send  " + JsonConvert.SerializeObject(notificationResponse));

                    Publisher orderSuccessNotificationPublisher = new Publisher(_configuration, notificationConfig.SNSTopic);

                    try
                    {
                        status = await orderSuccessNotificationPublisher.PublishAsync(notificationMessage);
                    }
                    catch (Exception ex)
                    {
                        LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) + "publishing :" + status);
                        throw ex;
                    }

                    LogInfo.Information("Email send status : " + status + " " + JsonConvert.SerializeObject(notificationMessage));

                    status = await SendOrderSuccessSMSNotification(customer, _configuration);

                    try
                    {
                        DatabaseResponse notificationLogResponse = await _configAccess.CreateEMailNotificationLogForDevPurpose(
                            new NotificationLogForDevPurpose
                        {
                            EventType = NotificationEvent.OrderSuccess.ToString(),
                            Message   = JsonConvert.SerializeObject(notificationMessage)
                        });
                    }
                    catch (Exception ex)
                    {
                        LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) + "Email send:" + OrderID);
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) + "OrderID:" + OrderID);
                throw ex;
            }

            return(status);
        }
Exemple #2
0
        public async Task <string> SendAdminEmailNotificationOnIDReUpload(string email, string orderNumber)
        {
            string status = string.Empty;

            try
            {
                ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration);

                DatabaseResponse templateResponse = await _configAccess.GetEmailNotificationTemplate(NotificationEvent.ICValidationCustomerUpload.ToString());

                DatabaseResponse notifyEmailResponse = ConfigHelper.GetValueByKey(ConfigKeys.IDReUploadNotifyEmail.ToString(), _iconfiguration);

                if (notifyEmailResponse.ResponseCode == (int)DbReturnValue.RecordExists && notifyEmailResponse.Results != null)
                {
                    var notificationMessage = MessageHelper.GetMessage((string)notifyEmailResponse.Results, "Admin", NotificationEvent.ICValidationCustomerUpload.ToString(), ((EmailTemplate)templateResponse.Results).TemplateName, _iconfiguration, email, orderNumber);

                    DatabaseResponse notificationResponse = await _configAccess.GetConfiguration(ConfiType.Notification.ToString());

                    MiscHelper parser = new MiscHelper();

                    var notificationConfig = parser.GetNotificationConfig((List <Dictionary <string, string> >)notificationResponse.Results);

                    LogInfo.Information("Email Message to send  " + JsonConvert.SerializeObject(notificationResponse));

                    Publisher orderSuccessNotificationPublisher = new Publisher(_iconfiguration, notificationConfig.SNSTopic);

                    try
                    {
                        status = await orderSuccessNotificationPublisher.PublishAsync(notificationMessage);
                    }
                    catch (Exception ex)
                    {
                        LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) + "publishing :" + status);
                        throw ex;
                    }

                    LogInfo.Information("Email send status : " + status + " " + JsonConvert.SerializeObject(notificationMessage));

                    try
                    {
                        DatabaseResponse notificationLogResponse = await _configAccess.CreateEMailNotificationLogForDevPurpose(

                            new NotificationLogForDevPurpose
                        {
                            EventType = NotificationEvent.OrderSuccess.ToString(),

                            Message = JsonConvert.SerializeObject(notificationMessage)
                        });
                    }
                    catch (Exception ex)
                    {
                        LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) + "Email send:" + email);
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) + "IDReUpload:" + email);
                throw ex;
            }

            return(status);
        }