Exemple #1
0
        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);
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets the message body by change request.
        /// </summary>
        /// <param name="changeRequestId">The change request identifier.</param>
        /// <returns></returns>
        public async Task <MessageBodyForCR> GetMessageBodyByChangeRequest(int changeRequestId)
        {
            try
            {
                DataSet        ds         = new DataSet();
                SqlParameter[] parameters =
                {
                    new SqlParameter("@ChangeRequestID", SqlDbType.Int),
                };

                parameters[0].Value = changeRequestId;

                _DataHelper = new DataAccessHelper(DbObjectNames.CR_GetMessageBody, parameters, _configuration);


                var result = await _DataHelper.RunAsync(ds);


                var msgBody = new MessageBodyForCR();

                if (ds.Tables.Count > 0)
                {
                    msgBody = (from model in ds.Tables[0].AsEnumerable()
                               select new MessageBodyForCR()
                    {
                        ChangeRequestID = model.Field <int>("ChangeRequestID"),
                        AccountID = model.Field <int>("AccountID"),
                        CustomerID = model.Field <int>("CustomerID"),
                        SubscriberID = model.Field <int?>("SubscriberID"),
                        OrderNumber = model.Field <string>("OrderNumber"),
                        RequestOn = model.Field <DateTime>("RequestOn"),
                        EffectiveDate = model.Field <DateTime?>("EffectiveDate"),
                        BillingUnit = model.Field <string>("BillingUnit"),
                        BillingFloor = model.Field <string>("BillingFloor"),
                        BillingBuildingNumber = model.Field <string>("BillingBuildingNumber"),
                        BillingBuildingName = model.Field <string>("BillingBuildingName"),
                        BillingStreetName = model.Field <string>("BillingStreetName"),
                        BillingPostCode = model.Field <string>("BillingPostCode"),
                        BillingContactNumber = model.Field <string>("BillingContactNumber"),
                        MobileNumber = model.Field <string>("MobileNumber"),
                        PremiumType = model.Field <int?>("PremiumType"),
                        IsPorted = model.Field <int?>("IsPorted"),
                        IsOwnNumber = model.Field <int?>("IsOwnNumber"),
                        DonorProvider = model.Field <string>("DonorProvider"),
                        PortedNumberTransferForm = model.Field <string>("PortedNumberTransferForm"),
                        PortedNumberOwnedBy = model.Field <string>("PortedNumberOwnedBy"),
                        PortedNumberOwnerRegistrationID = model.Field <string>("PortedNumberOwnerRegistrationID"),
                        Title = model.Field <string>("Title"),
                        Name = model.Field <string>("Name"),
                        Email = model.Field <string>("Email"),
                        Nationality = model.Field <string>("Nationality"),
                        IdType = model.Field <string>("IDType"),
                        IdNumber = model.Field <string>("IDNumber"),
                        IsSameAsBilling = model.Field <int?>("IsSameAsBilling"),
                        ShippingUnit = model.Field <string>("ShippingUnit"),
                        ShippingFloor = model.Field <string>("ShippingFloor"),
                        ShippingBuildingNumber = model.Field <string>("ShippingBuildingNumber"),
                        ShippingBuildingName = model.Field <string>("ShippingBuildingName"),
                        ShippingStreetName = model.Field <string>("ShippingStreetName"),
                        ShippingPostCode = model.Field <string>("ShippingPostCode"),
                        ShippingContactNumber = model.Field <string>("ShippingContactNumber"),
                        AlternateRecipientContact = model.Field <string>("AlternateRecipientContact"),
                        AlternateRecipientName = model.Field <string>("AlternateRecipientName"),
                        AlternateRecipientEmail = model.Field <string>("AlternateRecipientEmail"),
                        PortalSlotID = model.Field <string>("PortalSlotID"),
                        SlotDate = model.Field <DateTime?>("SlotDate"),
                        SlotFromTime = model.Field <TimeSpan?>("SlotFromTime"),
                        SlotToTime = model.Field <TimeSpan?>("SlotToTime"),
                        ScheduledDate = model.Field <DateTime?>("ScheduledDate"),
                        OldMobileNumber = model.Field <string>("OldMobileNumber"),
                        NewMobileNumber = model.Field <string>("NewMobileNumber"),
                        OldSIM = model.Field <string>("OldSIM"),
                        ServiceFee = model.Field <double?>("ServiceFee"),
                        AmountPaid = model.Field <double?>("AmountPaid"),
                        PaymentMode = model.Field <string>("PaymentMode"),
                        MPGSOrderID = model.Field <string>("MPGSOrderID"),
                        MaskedCardNumber = model.Field <string>("MaskedCardNumber"),
                        Token = model.Field <string>("Token"),
                        CardType = model.Field <string>("CardType"),
                        CardHolderName = model.Field <string>("CardHolderName"),
                        ExpiryMonth = model.Field <int?>("ExpiryMonth"),
                        ExpiryYear = model.Field <int?>("ExpiryYear"),
                        CardFundMethod = model.Field <string>("CardFundMethod"),
                        CardBrand = model.Field <string>("CardBrand"),
                        CardIssuer = model.Field <string>("CardIssuer"),
                        DateofBirth = model.Field <DateTime?>("DateofBirth"),
                        ReferralCode = model.Field <string>("ReferralCode"),
                        InvoiceUrl = model.Field <string>("InvoiceUrl"),
                        ProcessedOn = model.Field <DateTime?>("ProcessedOn"),
                        InvoiceNumber = model.Field <string>("InvoiceNumber"),
                    }).FirstOrDefault();

                    if (ds.Tables.Count > 1 && ds.Tables[1].Rows.Count != 0)
                    {
                        msgBody.Bundles = (from model in ds.Tables[1].AsEnumerable()
                                           select new BundleDetails()
                        {
                            BundleID = model.Field <int?>("BundleID"),
                            BSSPlanCode = model.Field <string>("BSSPlanCode"),
                            BSSPlanName = model.Field <string>("BSSPlanName"),
                            PlanType = model.Field <int?>("PlanType"),
                            OldBundleID = model.Field <int?>("OldBundleID"),
                            PlanMarketingName = model.Field <string>("PlanMarketingName"),
                            PortalDescription = model.Field <string>("PortalDescription"),
                            TotalData = model.Field <double?>("TotalData"),
                            TotalSMS = model.Field <double?>("TotalSMS"),
                            TotalVoice = model.Field <double?>("TotalVoice"),
                            ApplicableSubscriptionFee = model.Field <double?>("ApplicableSubscriptionFee"),
                            ServiceName = model.Field <string>("ServiceName"),
                            ApplicableServiceFee = model.Field <double?>("ApplicableServiceFee"),
                            OldPlanID = model.Field <int?>("OldPlanID"),
                            OldBSSPlanId = model.Field <string>("OldBSSPlanId"),
                            OldBSSPlanName = model.Field <string>("OldBSSPlanName"),
                        }).ToList();

                        msgBody.CurrBundles = (from model in ds.Tables[2].AsEnumerable()
                                               select new CurrBundleDetails()
                        {
                            BundleID = model.Field <int?>("BundleID"),
                            BSSPlanCode = model.Field <string>("BSSPlanCode"),
                            BSSPlanName = model.Field <string>("BSSPlanName"),
                            PlanType = model.Field <int?>("PlanType"),
                            StartDate = model.Field <DateTime?>("StartDate"),
                            ExpiryDate = model.Field <DateTime?>("ExpiryDate"),
                        }).ToList();
                    }
                    if (ds.Tables.Count > 2 && ds.Tables[3].Rows.Count != 0)
                    {
                        msgBody.Charges = (from model in ds.Tables[3].AsEnumerable()
                                           select new ChargesDetails()
                        {
                            ChangeRequestID = model.Field <int>("ChangeRequestID"),
                            SubscriberID = model.Field <int?>("SubscriberID"),
                            PortalServiceName = model.Field <string>("PortalServiceName"),
                            ServiceFee = model.Field <double?>("ServiceFee"),
                            IsRecurring = model.Field <int?>("IsRecurring"),
                            IsGSTIncluded = model.Field <int?>("IsGSTIncluded"),
                        }).ToList();
                    }
                }

                return(msgBody);
            }

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

                throw;
            }
            finally
            {
                _DataHelper.Dispose();
            }
        }
Exemple #3
0
        public async Task <BuyVASStatus> ProcessVas(int customerID, string mobileNumber, int bundleID, int quantity)
        {
            BuyVASStatus processVasStatus = new BuyVASStatus();

            try
            {
                OrderDataAccess _orderDataAccess = new OrderDataAccess(_iconfiguration);

                var statusResponse = await _orderDataAccess.BuyVasService(customerID, mobileNumber, bundleID, quantity);

                processVasStatus.BuyVASResponse = (BuyVASResponse)statusResponse.Results;

                processVasStatus.ResponseCode = statusResponse.ResponseCode;

                if (statusResponse.ResponseCode == (int)DbReturnValue.CreateSuccess)
                {
                    //Ninad K : Message Publish code
                    MessageBodyForCR            msgBody = new MessageBodyForCR();
                    Dictionary <string, string> attribute = new Dictionary <string, string>();
                    string topicName = string.Empty, subject = string.Empty;
                    try
                    {
                        topicName = ConfigHelper.GetValueByKey(ConfigKey.SNS_Topic_ChangeRequest.GetDescription(), _iconfiguration)
                                    .Results.ToString().Trim();

                        if (string.IsNullOrWhiteSpace(topicName))
                        {
                            throw new NullReferenceException("topicName is null for ChangeRequest (" + processVasStatus.BuyVASResponse.ChangeRequestID + ") for BuyVAS Request Service API");
                        }
                        msgBody = await _messageQueueDataAccess.GetMessageBodyByChangeRequest(processVasStatus.BuyVASResponse.ChangeRequestID);

                        if (msgBody == null || msgBody.ChangeRequestID == 0)
                        {
                            throw new NullReferenceException("message body is null for ChangeRequest (" + processVasStatus.BuyVASResponse.ChangeRequestID + ") for BuyVAS Service API");
                        }

                        attribute.Add(EventTypeString.EventType, Core.Enums.RequestType.AddVAS.GetDescription());
                        var 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.AddVAS.GetDescription().ToString(),
                                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.AddVAS.GetDescription().ToString(),
                                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.AddVAS.GetDescription().ToString(),
                            MessageBody                                 = msgBody != null?JsonConvert.SerializeObject(msgBody) : null,
                                                              Status    = 0,
                                                              Remark    = "Error Occured in BuyVASService",
                                                              Exception = new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)
                        };

                        await _messageQueueDataAccess.InsertMessageInMessageQueueRequestException(queueRequest);
                    }

                    processVasStatus.Result = 1;

                    return(processVasStatus);
                }
                else
                {
                    LogInfo.Warning(DbReturnValue.NoRecords.GetDescription());

                    processVasStatus.Result = 0;

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

                processVasStatus.Result = 0;

                return(processVasStatus);
            }
        }