public async Task <DatabaseResponse> GetOrderMessageQueueBody(int orderId) { try { SqlParameter[] parameters = { new SqlParameter("@OrderID", SqlDbType.Int) }; parameters[0].Value = orderId; _DataHelper = new DataAccessHelper("Orders_GetMessageQueueBody", parameters, _configuration); DataSet ds = new DataSet(); int result = await _DataHelper.RunAsync(ds); // 105 /102 DatabaseResponse response = new DatabaseResponse(); if (result == 105) { OrderQM order = new OrderQM(); if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { order = (from model in ds.Tables[0].AsEnumerable() select new OrderQM() { accountID = model.Field <int>("accountID"), customerID = model.Field <int>("customerID"), orderID = model.Field <int>("orderID"), orderNumber = model.Field <string>("orderNumber"), orderDate = model.Field <DateTime>("orderDate"), 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"), orderReferralCode = model.Field <string>("orderReferralCode"), 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"), submissionDate = model.Field <DateTime>("submissionDate"), 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"), ProcessedOn = model.Field <DateTime?>("ProcessedOn"), InvoiceNumber = model.Field <string>("InvoiceNumber"), InvoiceUrl = model.Field <string>("InvoiceUrl"), CreatedOn = model.Field <DateTime>("CreatedOn") }).FirstOrDefault(); List <OrderSubscriber> Subscribers = new List <OrderSubscriber>(); if (ds.Tables[1] != null && ds.Tables[1].Rows.Count > 0) { List <OrderSubscriptionQM> Bundles = new List <OrderSubscriptionQM>(); if (ds.Tables[2] != null && ds.Tables[2].Rows.Count > 0) { Bundles = (from model in ds.Tables[2].AsEnumerable() select new OrderSubscriptionQM() { SubscriberID = model.Field <int>("SubscriberID"), bundleID = model.Field <int>("bundleID"), bssPlanCode = model.Field <string>("bssPlanCode"), bssPlanName = model.Field <string>("bssPlanName"), planType = model.Field <int>("planType"), 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") }).ToList(); } Subscribers = (from model in ds.Tables[1].AsEnumerable() select new OrderSubscriber() { OrderID = model.Field <int>("OrderID"), subscriberID = model.Field <int>("subscriberID"), mobileNumber = model.Field <string>("mobileNumber"), displayName = model.Field <string>("displayName"), isPrimaryNumber = model.Field <int>("isPrimaryNumber"), premiumType = model.Field <int?>("premiumType"), isPorted = model.Field <int?>("isPorted"), isOwnNumber = model.Field <int?>("isOwnNumber"), donorProvider = model.Field <string>("donorProvider"), DepositFee = model.Field <double?>("DepositFee"), IsBuddyLine = model.Field <int?>("IsBuddyLine"), LinkedSubscriberID = model.Field <int?>("LinkedSubscriberID"), RefOrderSubscriberID = model.Field <int?>("RefOrderSubscriberID"), portedNumberTransferForm = model.Field <string>("portedNumberTransferForm"), portedNumberOwnedBy = model.Field <string>("portedNumberOwnedBy"), portedNumberOwnerRegistrationID = model.Field <string>("portedNumberOwnerRegistrationID"), Bundles = Bundles != null ? Bundles.Where(b => b.SubscriberID == model.Field <int>("subscriberID")).ToList() : null }).ToList(); order.Subscribers = Subscribers; } List <OrderServiceCharge> serviceCharges = new List <OrderServiceCharge>(); if (ds.Tables[3] != null && ds.Tables[3].Rows.Count > 0) { serviceCharges = (from model in ds.Tables[3].AsEnumerable() select new OrderServiceCharge() { OrderID = model.Field <int>("OrderID"), SubscriberID = model.Field <int?>("SubscriberID"), AdminServiceID = model.Field <int?>("AdminServiceID"), portalServiceName = model.Field <string>("portalServiceName"), serviceFee = model.Field <double?>("serviceFee"), isRecurring = model.Field <int>("isRecurring"), isGSTIncluded = model.Field <int>("isGSTIncluded"), }).ToList(); order.Charges = serviceCharges; } } response = new DatabaseResponse { ResponseCode = result, Results = order }; } else { response = new DatabaseResponse { ResponseCode = result }; } return(response); } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); throw (ex); } finally { _DataHelper.Dispose(); } }
public async Task <int> ProcessOrderQueueMessage(int orderID) { try { BuddyDataAccess _buddyAccess = new BuddyDataAccess(); QMDataAccess _qMDataAccess = new QMDataAccess(); DatabaseResponse orderMqResponse = new DatabaseResponse(); orderMqResponse = await _qMDataAccess.GetOrderMessageQueueBody(orderID, _connectionString); OrderQM orderDetails = new OrderQM(); string topicName = ConfigHelper.GetValueByKey(ConfigKey.SNS_Topic_ChangeRequest.GetDescription(), _connectionString).Results.ToString().Trim(); string pushResult = string.Empty; if (orderMqResponse != null && orderMqResponse.Results != null) { orderDetails = (OrderQM)orderMqResponse.Results; DatabaseResponse OrderCountResponse = await _qMDataAccess.GetCustomerOrderCount(orderDetails.customerID, _connectionString); MessageQueueRequest queueRequest = new MessageQueueRequest { Source = CheckOutType.Orders.ToString(), NumberOfRetries = 1, SNSTopic = topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = ((int)OrderCountResponse.Results) == 1 ? Core.Enums.RequestType.NewCustomer.GetDescription() : Core.Enums.RequestType.NewService.GetDescription(), MessageBody = JsonConvert.SerializeObject(orderDetails), Status = 0 }; try { Dictionary <string, string> attribute = new Dictionary <string, string>(); DatabaseResponse configValueResponse = ConfigHelper.GetValueByKey(ConfigKey.SNS_Topic_ChangeRequest.GetDescription(), _connectionString); topicName = (string)configValueResponse.Results; attribute.Add(EventTypeString.EventType, ((int)OrderCountResponse.Results) == 1 ? Core.Enums.RequestType.NewCustomer.GetDescription() : Core.Enums.RequestType.NewService.GetDescription()); var publisher = new InfrastructureService.MessageQueue.Publisher(_connectionString, topicName); pushResult = await publisher.PublishAsync(orderDetails, attribute); if (pushResult.Trim().ToUpper() == "OK") { queueRequest.Status = 1; queueRequest.PublishedOn = DateTime.Now; LogInfo.Information(EnumExtensions.GetDescription(CommonErrors.PendingBuddyOrderProcessed)); await _buddyAccess.InsertMessageInMessageQueueRequest(queueRequest, _connectionString); return(1); } else { // publising failed queueRequest.Status = 0; await _buddyAccess.InsertMessageInMessageQueueRequest(queueRequest, _connectionString); return(0); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); MessageQueueRequestException queueExceptionRequest = new MessageQueueRequestException { Source = CheckOutType.Orders.ToString(), NumberOfRetries = 1, SNSTopic = string.IsNullOrWhiteSpace(topicName) ? null : topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = Core.Enums.RequestType.RescheduleDelivery.GetDescription().ToString(), MessageBody = orderDetails != null?JsonConvert.SerializeObject(orderDetails) : null, Status = 0, Remark = "Critical Exception while sending MQ from buddy console", Exception = new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) }; await _buddyAccess.InsertMessageInMessageQueueRequestException(queueExceptionRequest, _connectionString); return(0); } } else { LogInfo.Information(EnumExtensions.GetDescription(CommonErrors.PendingBuddyMQBodyFailed)); return(0); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); return(0); } }
public async void ProcessOrderQueueMessage(int orderID) { try { OrderDataAccess _orderAccess = new OrderDataAccess(_iconfiguration); DatabaseResponse orderMqResponse = new DatabaseResponse(); orderMqResponse = await _messageQueueDataAccess.GetOrderMessageQueueBody(orderID); OrderQM orderDetails = new OrderQM(); string topicName = string.Empty; string pushResult = string.Empty; if (orderMqResponse != null && orderMqResponse.Results != null) { orderDetails = (OrderQM)orderMqResponse.Results; DatabaseResponse OrderCountResponse = await _orderAccess.GetCustomerOrderCount(orderDetails.customerID); try { Dictionary <string, string> attribute = new Dictionary <string, string>(); topicName = ConfigHelper.GetValueByKey(ConfigKey.SNS_Topic_ChangeRequest.GetDescription(), _iconfiguration).Results.ToString().Trim(); if (string.IsNullOrWhiteSpace(topicName)) { throw new NullReferenceException("topicName is null for Order (" + orderID + ") for RemoveVAS Request Service API"); } attribute.Add(EventTypeString.EventType, ((OrderCount)OrderCountResponse.Results).SuccessfulOrders == 1 ? Core.Enums.RequestType.NewCustomer.GetDescription() : Core.Enums.RequestType.NewService.GetDescription()); pushResult = await _messageQueueDataAccess.PublishMessageToMessageQueue(topicName, orderDetails, attribute); if (pushResult.Trim().ToUpper() == "OK") { MessageQueueRequest queueRequest = new MessageQueueRequest { Source = CheckOutType.Orders.ToString(), NumberOfRetries = 1, SNSTopic = topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = ((OrderCount)OrderCountResponse.Results).SuccessfulOrders == 1 ? Core.Enums.RequestType.NewCustomer.GetDescription() : Core.Enums.RequestType.NewService.GetDescription(), MessageBody = JsonConvert.SerializeObject(orderDetails), Status = 1 }; await _messageQueueDataAccess.InsertMessageInMessageQueueRequest(queueRequest); } else { MessageQueueRequest queueRequest = new MessageQueueRequest { Source = CheckOutType.Orders.ToString(), NumberOfRetries = 1, SNSTopic = topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = ((OrderCount)OrderCountResponse.Results).SuccessfulOrders == 1 ? Core.Enums.RequestType.NewCustomer.GetDescription() : Core.Enums.RequestType.NewService.GetDescription(), MessageBody = orderDetails != null?JsonConvert.SerializeObject(orderDetails) : null, Status = 0 }; await _messageQueueDataAccess.InsertMessageInMessageQueueRequest(queueRequest); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); MessageQueueRequestException queueRequest = new MessageQueueRequestException { Source = CheckOutType.Orders.ToString(), NumberOfRetries = 1, SNSTopic = topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = ((OrderCount)OrderCountResponse.Results).SuccessfulOrders == 1 ? Core.Enums.RequestType.NewCustomer.GetDescription() : Core.Enums.RequestType.NewService.GetDescription(), MessageBody = JsonConvert.SerializeObject(orderDetails), Status = 0 }; await _messageQueueDataAccess.InsertMessageInMessageQueueRequestException(queueRequest); } } } catch (Exception ex) { throw ex; } }