コード例 #1
0
ファイル: QMHelper.cs プロジェクト: santhign/Grid
        public async Task <string> SendEmailNotification(string MPGSOrderID, int orderID)
        {
            string status = string.Empty;

            LogInfo.Information("Email orderID : " + orderID);

            LogInfo.Information("Email MPGSOrderID : " + MPGSOrderID);

            try
            {
                OrderDataAccess _orderAccess = new OrderDataAccess(_iconfiguration);

                CommonDataAccess _commonAccess = new CommonDataAccess(_iconfiguration);

                ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration);

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

                // customerID,
                DatabaseResponse customerResponse = await _orderAccess.GetCustomerIdFromOrderId(orderID);

                LogInfo.Information("Email Customer : " + (int)((OrderCustomer)customerResponse.Results).CustomerId);
                // Get Customer Data from CustomerID for email and Name
                CustomerDetails customer = await _commonAccess.GetCustomerDetailByOrder(((OrderCustomer)customerResponse.Results).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%'>Mobile Number :<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);
                    }
                    if (deliveryAddressSb.ToString() != "")
                    {
                        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);
                    }
                    if (shippingAddr2.ToString() != "")
                    {
                        deliveryAddressSb.Append(shippingAddr2.ToString());

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

                    if (!string.IsNullOrEmpty(customer.ShippingPostCode))
                    {
                        deliveryAddressSb.Append("Singapore - " + 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, _iconfiguration, 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(_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));

                    status = await SendOrderSuccessSMSNotification(customer, NotificationEvent.OrderSuccess.ToString());

                    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:" + MPGSOrderID);
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) + "MPGS OrderID:" + MPGSOrderID);
                throw ex;
            }

            return(status);
        }
コード例 #2
0
ファイル: QMHelper.cs プロジェクト: santhign/Grid
        public async Task <int> ProcessSuccessTransaction(CheckOutResponseUpdate updateRequest)
        {
            try
            {
                OrderDataAccess _orderAccess = new OrderDataAccess(_iconfiguration);

                DatabaseResponse sourceTyeResponse = new DatabaseResponse();

                sourceTyeResponse = await _orderAccess.GetSourceTypeByMPGSSOrderId(updateRequest.MPGSOrderID);

                if (sourceTyeResponse.ResponseCode == (int)DbReturnValue.RecordExists)
                {
                    if (((OrderSource)sourceTyeResponse.Results).SourceType == CheckOutType.ChangeRequest.ToString())
                    {
                        var details = await _messageQueueDataAccess.GetMessageDetails(updateRequest.MPGSOrderID);

                        if (details != null)
                        {
                            MessageBodyForCR msgBody = new MessageBodyForCR();

                            string topicName = string.Empty, pushResult = string.Empty;

                            try
                            {
                                Dictionary <string, string> attribute = new Dictionary <string, string>();

                                msgBody = await _messageQueueDataAccess.GetMessageBodyByChangeRequest(details.ChangeRequestID);

                                DatabaseResponse changeRequestTypeResponse = await _orderAccess.GetChangeRequestTypeFromID(details.ChangeRequestID);

                                if (((string)changeRequestTypeResponse.Results) == NotificationEvent.ReplaceSIM.ToString())
                                {
                                    if (msgBody.SlotDate != null)
                                    {
                                        CustomerDetails customer = new CustomerDetails
                                        {
                                            Name                  = msgBody.Name,
                                            DeliveryEmail         = msgBody.Email,
                                            ShippingContactNumber = msgBody.ShippingContactNumber,
                                            OrderNumber           = msgBody.OrderNumber,
                                            SlotDate              = msgBody.SlotDate ?? DateTime.Now,
                                            SlotFromTime          = msgBody.SlotFromTime ?? DateTime.Now.TimeOfDay,
                                            SlotToTime            = msgBody.SlotToTime ?? DateTime.Now.TimeOfDay
                                        };

                                        string status = await SendOrderSuccessSMSNotification(customer, NotificationEvent.ReplaceSIM.ToString());
                                    }
                                }

                                if (details.RequestTypeID == (int)Core.Enums.RequestType.ReplaceSIM)
                                {
                                    topicName = ConfigHelper.GetValueByKey(ConfigKey.SNS_Topic_ChangeRequest.GetDescription(), _iconfiguration).Results.ToString().Trim();
                                    attribute.Add(EventTypeString.EventType, Core.Enums.RequestType.ReplaceSIM.GetDescription());
                                    pushResult = await _messageQueueDataAccess.PublishMessageToMessageQueue(topicName, msgBody, attribute);
                                }
                                if (pushResult.Trim().ToUpper() == "OK")
                                {
                                    MessageQueueRequest queueRequest = new MessageQueueRequest
                                    {
                                        Source           = Source.ChangeRequest,
                                        NumberOfRetries  = 1,
                                        SNSTopic         = topicName,
                                        CreatedOn        = DateTime.Now,
                                        LastTriedOn      = DateTime.Now,
                                        PublishedOn      = DateTime.Now,
                                        MessageAttribute = Core.Enums.RequestType.ReplaceSIM.GetDescription(),
                                        MessageBody      = JsonConvert.SerializeObject(msgBody),
                                        Status           = 1
                                    };
                                    await _messageQueueDataAccess.InsertMessageInMessageQueueRequest(queueRequest);
                                }
                                else
                                {
                                    MessageQueueRequest queueRequest = new MessageQueueRequest
                                    {
                                        Source           = Source.ChangeRequest,
                                        NumberOfRetries  = 1,
                                        SNSTopic         = topicName,
                                        CreatedOn        = DateTime.Now,
                                        LastTriedOn      = DateTime.Now,
                                        PublishedOn      = DateTime.Now,
                                        MessageAttribute = Core.Enums.RequestType.ReplaceSIM.GetDescription(),
                                        MessageBody      = JsonConvert.SerializeObject(msgBody),
                                        Status           = 0
                                    };
                                    await _messageQueueDataAccess.InsertMessageInMessageQueueRequest(queueRequest);
                                }
                            }
                            catch (Exception ex)
                            {
                                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
                                MessageQueueRequestException queueRequest = new MessageQueueRequestException
                                {
                                    Source                                      = Source.ChangeRequest,
                                    NumberOfRetries                             = 1,
                                    SNSTopic                                    = string.IsNullOrWhiteSpace(topicName) ? null : topicName,
                                    CreatedOn                                   = DateTime.Now,
                                    LastTriedOn                                 = DateTime.Now,
                                    PublishedOn                                 = DateTime.Now,
                                    MessageAttribute                            = Core.Enums.RequestType.ReplaceSIM.GetDescription().ToString(),
                                    MessageBody                                 = msgBody != null?JsonConvert.SerializeObject(msgBody) : null,
                                                                      Status    = 0,
                                                                      Remark    = "Error Occured in ProcessSuccessTransaction",
                                                                      Exception = new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)
                                };

                                await _messageQueueDataAccess.InsertMessageInMessageQueueRequestException(queueRequest);
                            }
                        }

                        return(3);
                    }

                    else if (((OrderSource)sourceTyeResponse.Results).SourceType == CheckOutType.Orders.ToString())
                    {
                        try
                        {
                            LogInfo.Information("Calling SendEmailNotification");
                            string emailStatus = await SendEmailNotification(updateRequest.MPGSOrderID, ((OrderSource)sourceTyeResponse.Results).SourceID);

                            LogInfo.Information("Email Send status for : " + emailStatus);
                        }

                        catch (Exception ex)
                        {
                            LogInfo.Information("Email Send failed");
                            LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
                        }

                        ProcessOrderQueueMessage(((OrderSource)sourceTyeResponse.Results).SourceID);

                        BuddyHelper buddyHelper = new BuddyHelper(_iconfiguration, _messageQueueDataAccess);

                        // Proess VAS bundles added to Order

                        DatabaseResponse getVASToProcessResponse = await _orderAccess.GetOrderedVASesToProcess(((OrderSource)sourceTyeResponse.Results).SourceID);

                        LogInfo.Information("Processing VASes for Order:" + ((OrderSource)sourceTyeResponse.Results).SourceID);

                        if (getVASToProcessResponse.ResponseCode == (int)DbReturnValue.RecordExists && getVASToProcessResponse.Results != null)
                        {
                            List <VasToProcess> vasListToProcess = (List <VasToProcess>)getVASToProcessResponse.Results;

                            LogInfo.Information(" VAS list to Process for Order:" + +((OrderSource)sourceTyeResponse.Results).SourceID + " - " + JsonConvert.SerializeObject(vasListToProcess));

                            DatabaseResponse customerResponse = await _orderAccess.GetCustomerIdFromOrderId(((OrderSource)sourceTyeResponse.Results).SourceID);

                            if (customerResponse != null && customerResponse.ResponseCode == (int)DbReturnValue.RecordExists)
                            {
                                int customerID = ((OrderCustomer)customerResponse.Results).CustomerId;

                                foreach (VasToProcess vas in vasListToProcess)
                                {
                                    BuyVASStatus vasProcessStatus = await buddyHelper.ProcessVas(customerID, vas.MobileNumber, vas.BundleID, 1);
                                }
                            }
                        }

                        return(3); // not buddy plan; MQ send
                    }

                    else if (((OrderSource)sourceTyeResponse.Results).SourceType == CheckOutType.AccountInvoices.ToString())
                    {
                        //send invoice queue message

                        ProcessAccountInvoiceQueueMessage(((OrderSource)sourceTyeResponse.Results).SourceID);

                        return(3);
                    }

                    else
                    {
                        return(5); // incorrect CheckOutType, no chance to reach here, but just to do
                                   //returnn from all code path, because in all of the above I need to keep CheckOutType check
                    }
                }

                else
                {
                    // unable to get sourcetype form db

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