Beispiel #1
0
        public async Task <BuddyCheckList> ProcessBuddy(BuddyCheckList buddy)
        {
            try
            {
                BSSAPIHelper bsshelper = new BSSAPIHelper();

                BuddyDataAccess _buddyAccess = new BuddyDataAccess();

                DatabaseResponse configResponse = await _buddyAccess.GetConfiguration(ConfiType.BSS.ToString(), _connectionString);

                GridBSSConfi config = bsshelper.GetGridConfig((List <Dictionary <string, string> >)configResponse.Results);

                LogInfo.Information(JsonConvert.SerializeObject(config));

                DatabaseResponse serviceCAF = await _buddyAccess.GetBSSServiceCategoryAndFee(ServiceTypes.Free.ToString(), _connectionString);

                DatabaseResponse requestIdRes = await _buddyAccess.GetBssApiRequestId(GridMicroservices.Order.ToString(), BSSApis.GetAssets.ToString(), buddy.CustomerID, (int)BSSCalls.NewSession, "", _connectionString);

                ResponseObject res = new ResponseObject();

                try
                {
                    res = await bsshelper.GetAssetInventory(config, (((List <ServiceFees>)serviceCAF.Results)).FirstOrDefault().ServiceCode, (BSSAssetRequest)requestIdRes.Results);

                    LogInfo.Information(JsonConvert.SerializeObject(res));
                }

                catch (Exception ex)
                {
                    LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) + EnumExtensions.GetDescription(CommonErrors.BSSConnectionFailed));
                    buddy.IsProcessed = false;
                    return(buddy);
                }

                string AssetToSubscribe = string.Empty;

                if (res != null && (int.Parse(res.Response.asset_details.total_record_count) > 0))
                {
                    AssetToSubscribe = bsshelper.GetAssetId(res);

                    BSSNumbers numbers = new BSSNumbers();

                    numbers.FreeNumbers = bsshelper.GetFreeNumbers(res);

                    //insert these number into database
                    string json = bsshelper.GetJsonString(numbers.FreeNumbers); // json insert

                    DatabaseResponse updateBssCallFeeNumbers = await _buddyAccess.UpdateBSSCallNumbers(json, ((BSSAssetRequest)requestIdRes.Results).userid, ((BSSAssetRequest)requestIdRes.Results).BSSCallLogID, _connectionString);

                    //Block number                                    _connectionString
                    DatabaseResponse requestIdToUpdateRes = await _buddyAccess.GetBssApiRequestId(GridMicroservices.Order.ToString(), BSSApis.UpdateAssetStatus.ToString(), buddy.CustomerID, (int)BSSCalls.ExistingSession, AssetToSubscribe, _connectionString);

                    BSSUpdateResponseObject bssUpdateResponse = new BSSUpdateResponseObject();

                    try
                    {
                        bssUpdateResponse = await bsshelper.UpdateAssetBlockNumber(config, (BSSAssetRequest)requestIdToUpdateRes.Results, AssetToSubscribe, false);
                    }

                    catch (Exception ex)
                    {
                        LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) + EnumExtensions.GetDescription(CommonErrors.BSSConnectionFailed));
                        buddy.IsProcessed = false;
                        return(buddy);
                    }


                    if (bssUpdateResponse != null && bsshelper.GetResponseCode(bssUpdateResponse) == "0")
                    {
                        // update buddy process

                        BuddyNumberUpdate buddyToProcess = new BuddyNumberUpdate {
                            OrderSubscriberID = buddy.OrderSubscriberID, UserId = ((BSSAssetRequest)requestIdRes.Results).userid, NewMobileNumber = AssetToSubscribe
                        };

                        LogInfo.Information(JsonConvert.SerializeObject(buddyToProcess));

                        DatabaseResponse buddyProcessResponse = await _buddyAccess.ProcessBuddyPlan(buddyToProcess, _connectionString);

                        LogInfo.Information(JsonConvert.SerializeObject(buddyProcessResponse));

                        if (buddyProcessResponse.ResponseCode == (int)DbReturnValue.CreateSuccess || buddyProcessResponse.ResponseCode == (int)DbReturnValue.BuddyAlreadyExists)
                        {
                            // update process status

                            buddy.IsProcessed = true;

                            return(buddy);
                        }

                        else
                        {
                            // buddy process failed
                            buddy.IsProcessed = false;

                            return(buddy);
                        }
                    }
                    else
                    {
                        // buddy block failed
                        buddy.IsProcessed = false;

                        return(buddy);
                    }
                }
                else
                {
                    // no assets returned
                    buddy.IsProcessed = false;
                    return(buddy);
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                buddy.IsProcessed = false;

                return(buddy);
            }
        }
Beispiel #2
0
        public async Task <int> ProcessBuddy(BuddyCheckList buddy, GridBSSConfi config, int serviceCode)
        {
            try
            {
                BSSAPIHelper bsshelper = new BSSAPIHelper();

                OrderDataAccess _orderAccess = new OrderDataAccess(_iconfiguration);

                DatabaseResponse requestIdRes = await _orderAccess.GetBssApiRequestId(GridMicroservices.Order.ToString(), BSSApis.GetAssets.ToString(), buddy.CustomerID, (int)BSSCalls.NewSession, "");

                ResponseObject res = new ResponseObject();

                try
                {
                    res = await bsshelper.GetAssetInventory(config, serviceCode, (BSSAssetRequest)requestIdRes.Results);
                }

                catch (Exception ex)
                {
                    LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) + EnumExtensions.GetDescription(CommonErrors.BSSConnectionFailed));

                    buddy.IsProcessed = false;

                    return(0);
                }

                string AssetToSubscribe = string.Empty;

                if (res != null)
                {
                    AssetToSubscribe = bsshelper.GetAssetId(res);

                    BSSNumbers numbers = new BSSNumbers();

                    numbers.FreeNumbers = bsshelper.GetFreeNumbers(res);

                    //insert these number into database
                    string json = bsshelper.GetJsonString(numbers.FreeNumbers); // json insert

                    DatabaseResponse updateBssCallFeeNumbers = await _orderAccess.UpdateBSSCallNumbers(json, ((BSSAssetRequest)requestIdRes.Results).userid, ((BSSAssetRequest)requestIdRes.Results).BSSCallLogID);
                }

                else
                {
                    return(0);
                }

                if (res != null && (int.Parse(res.Response.asset_details.total_record_count) > 0))
                {
                    //Block number

                    DatabaseResponse requestIdToUpdateRes = await _orderAccess.GetBssApiRequestId(GridMicroservices.Order.ToString(), BSSApis.UpdateAssetStatus.ToString(), buddy.CustomerID, (int)BSSCalls.ExistingSession, AssetToSubscribe);

                    BSSUpdateResponseObject bssUpdateResponse = await bsshelper.UpdateAssetBlockNumber(config, (BSSAssetRequest)requestIdToUpdateRes.Results, AssetToSubscribe, false);

                    if (bsshelper.GetResponseCode(bssUpdateResponse) == "0")
                    {
                        // update buddy process

                        BuddyNumberUpdate buddyToProcess = new BuddyNumberUpdate {
                            OrderSubscriberID = buddy.OrderSubscriberID, UserId = ((BSSAssetRequest)requestIdRes.Results).userid, NewMobileNumber = AssetToSubscribe
                        };

                        DatabaseResponse buddyProcessResponse = await _orderAccess.ProcessBuddyPlan(buddyToProcess);

                        if (buddyProcessResponse.ResponseCode == (int)DbReturnValue.CreateSuccess)
                        {
                            // update process status

                            buddy.IsProcessed = true;

                            return(1);
                        }

                        else
                        {
                            // buddy process failed
                            buddy.IsProcessed = false;

                            return(0);
                        }
                    }
                    else
                    {
                        // buddy block failed
                        buddy.IsProcessed = false;

                        LogInfo.Error(EnumExtensions.GetDescription(CommonErrors.UpdateAssetBlockingFailed));

                        return(0);
                    }
                }
                else
                {
                    // no assets returned
                    buddy.IsProcessed = false;
                    LogInfo.Error(EnumExtensions.GetDescription(CommonErrors.GetAssetFailed));

                    return(0);
                }
            }
            catch (Exception ex)
            {
                buddy.IsProcessed = false;

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

                return(0);
            }
        }