Пример #1
0
        public async Task <string> SendOrderSuccessSMSNotification(CustomerDetails customer, IConfiguration _configuration)
        {
            string status = string.Empty;

            try
            {
                ConfigDataAccess _configAccess = new ConfigDataAccess(_configuration);

                DatabaseResponse smsTemplateResponse = await _configAccess.GetSMSNotificationTemplate(NotificationEvent.OrderSuccess.ToString());

                var notificationMessage = MessageHelper.GetSMSMessage(NotificationEvent.OrderSuccess.ToString(), ((SMSTemplates)smsTemplateResponse.Results).TemplateName, customer.Name, customer.DeliveryEmail, customer.ShippingContactNumber, customer.OrderNumber, 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"));

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

                MiscHelper parser = new MiscHelper();

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

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

                status = await orderSuccessSMSNotificationPublisher.PublishAsync(notificationMessage);

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

                return(status);
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) + "SMS failure for OrderNumber:" + customer.OrderNumber);

                throw ex;
            }
        }
        public async void ProcessNotification(object message)
        {
            try
            {
                Amazon.SQS.Model.Message msg = (Amazon.SQS.Model.Message)message;

                string queMessage = msg.Body;
                //LogInfo.Information("8 - bsubscription is  {" + msg.MessageId + "} object");
                SNSSubscription subscription = JsonConvert.DeserializeObject <SNSSubscription>(queMessage);

                //LogInfo.Information("8 - bsubscription is  {" + subscription.MessageId + "} object");
                NotificationMessage NotMessage = JsonConvert.DeserializeObject <NotificationMessage>(subscription.Message);
                //LogInfo.Information("9 - NotMessage is  {" + NotMessage.Message +" "+ NotMessage.MessageType + "} object");
                // SNSSubscription messageObject= new SNSSubscription {  Message=me};

                //   NotificationMessage notification= JsonConvert.DeserializeObject<NotificationMessage>(messageObject.Message);
                if (NotMessage.MessageType == NotificationMsgType.Email.GetDescription())
                {
                    OutboundEmail _email = new OutboundEmail();

                    ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration);

                    DatabaseResponse emailTemplate = await _configAccess.GetEmailNotificationTemplate(NotMessage.Message.messagetemplate.ToString());

                    EmailTemplate template = (EmailTemplate)emailTemplate.Results;

                    var responses = await _email.SendEmail(NotMessage, _iconfiguration, template);


                    foreach (Mandrill.Model.MandrillSendMessageResponse response in responses)
                    {
                        foreach (NotificationParams param in NotMessage.Message.parameters)
                        {
                            if (response.Email == param.emailaddress)
                            {
                                DatabaseResponse notificationLogResponse = await _configAccess.CreateEMailNotificationLog(new NotificationLog {
                                    Status          = response.Status.ToString() == "Sent" ? 1 : 0, Email = response.Email,
                                    EmailTemplateID = template.EmailTemplateID, EmailBody = template.EmailBody,
                                    EmailSubject    = template.EmailSubject, ScheduledOn = subscription.Timestamp, SendOn = DateTime.Now
                                });
                            }
                        }
                    }
                }
                else if (NotMessage.MessageType == NotificationMsgType.SMS.GetDescription())
                {
                    OutboundSMS      _SMS          = new OutboundSMS();
                    TextMessage      smsData       = new TextMessage();
                    ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration);

                    DatabaseResponse smsTemplate = await _configAccess.GetSMSNotificationTemplate(NotMessage.Message.messagetemplate.ToString());

                    SMSTemplates template = (SMSTemplates)smsTemplate.Results;

                    foreach (var item in NotMessage.Message.parameters)
                    {
                        smsData.PhoneNumber = item.mobilenumber;

                        smsData.SMSText = template.SMSTemplate.Replace("*|NAME|*", item.name)
                                          .Replace("*|PARAM1|*", item.param1)
                                          .Replace("*|PARAM2|*", item.param2)
                                          .Replace("*|PARAM3|*", item.param3)
                                          .Replace("*|PARAM4|*", item.param4)
                                          .Replace("*|PARAM5|*", item.param5)
                                          .Replace("*|PARAM6|*", item.param6)
                                          .Replace("*|PARAM7|*", item.param7)
                                          .Replace("*|PARAM8|*", item.param8)
                                          .Replace("*|PARAM9|*", item.param9)
                                          .Replace("*|PARAM10|*", item.param10);
                        //LogInfo.Information("10 - SendSMS is  { "+ smsData+ "}");
                        string response = await _SMS.SendSMSNotification(smsData, _iconfiguration);

                        await _configAccess.CreateSMSNotificationLog(new SMSNotificationLog()
                        {
                            Email         = NotMessage.Message.parameters.Select(x => x.emailaddress).FirstOrDefault(),
                            Mobile        = smsData.PhoneNumber,
                            SMSTemplateID = template.SMSTemplateID,
                            SMSText       = smsData.SMSText,
                            Status        = response != "failure" ? 1 : 0,
                            ScheduledOn   = subscription.Timestamp,
                            SendOn        = DateTime.Now
                        });
                    }

                    //LogInfo.Information("10 - SendSMSLog is  { " + NotMessage.Message.parameters.Select(x => x.emailaddress).FirstOrDefault() + " " + smsData.PhoneNumber + " "+ response + "}");
                }
            }

            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
            }
        }