public async Task <IActionResult> PushEmail([FromBody] NotificationMessage emailSubscribers) { try { if (!ModelState.IsValid) { LogInfo.Error(StatusMessages.DomainValidationError); new OperationResponse { HasSucceeded = false, IsDomainValidationErrors = true, Message = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)) }; } OutboundEmail _email = new OutboundEmail(); ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration); DatabaseResponse forgotPasswordMsgTemplate = await _configAccess.GetEmailNotificationTemplate(NotificationEvent.ForgetPassword.ToString()); EmailTemplate template = (EmailTemplate)forgotPasswordMsgTemplate.Results; var responses = await _email.SendEmail(emailSubscribers, _iconfiguration, template); foreach (Mandrill.Model.MandrillSendMessageResponse response in responses) { //DatabaseResponse notificationLogResponse = await _configAccess.CreateEMailNotificationLog(new NotificationLog { Status=response.Status.ToString(), Email=response.Email }); } // log notificaiton in db return(Ok(new ServerResponse { HasSucceeded = true, Message = StatusMessages.SuccessMessage })); } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); return(Ok(new OperationResponse { HasSucceeded = false, Message = StatusMessages.ServerError, IsDomainValidationErrors = false })); } }
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); }
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); }
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)); } }