Ejemplo n.º 1
0
        public AirtimeServiceResponse SwitchDataVendors(IEnumerable <IAirtimeService> airtimeServices)
        {
            AirtimeServiceResponse airtimeServiceResponse = new AirtimeServiceResponse();

            var _Vendoragents = Vendors.AllVendors();

            string[] allActiveVendors = this._DataPackages.GetAllPackageVendors(this.PackageId);

            if (allActiveVendors.Length != 0)
            {
                for (int i = 0; i < allActiveVendors.Length; i++)
                {
                    Vendors NewActiveVendor = _Vendoragents.Where(x => x.Name.ToLower() == allActiveVendors[i].ToLower()).FirstOrDefault();
                    if (NewActiveVendor != null)
                    {
                        airtimeServiceResponse = airtimeServices
                                                 .FirstOrDefault(x => x.AgentName().ToLower() == allActiveVendors[i].ToLower())
                                                 .BuyData(this);

                        //airtimeServiceResponse = airtimeServices
                        //    .FirstOrDefault(x => x.AgentName().ToLower() == "CWG".ToLower())
                        //    .BuyData(this);
                        //airtimeServiceResponse.ProccedByVendorId = "1";

                        NewActiveVendor.DateUpdated = DateTime.Now;

                        if (airtimeServiceResponse?.ResponseStatus == TransactionStatus.Success.ToString())
                        {
                            vendorId = NewActiveVendor.Id;
                            airtimeServiceResponse.ProccedByVendorId = vendorId.ToString();
                            break;
                        }

                        if (airtimeServiceResponse?.ResponseStatus == TransactionStatus.Pending.ToString())
                        {
                            airtimeServiceResponse.ProccedByVendorId = NewActiveVendor.Id.ToString();
                            vendorId = NewActiveVendor.Id;
                            break;
                        }

                        if (airtimeServiceResponse?.ResponseStatus == TransactionStatus.Failed.ToString())
                        {
                            airtimeServiceResponse.ProccedByVendorId = NewActiveVendor.Id.ToString();
                            vendorId = NewActiveVendor.Id;
                        }
                    }
                    else
                    {
                        airtimeServiceResponse.ResponseStatus    = TransactionStatus.Failed.ToString();
                        airtimeServiceResponse.ResponseMessage   = AirtimeValidationMessages.ErrorMessages.InvalidDataPackageId;
                        airtimeServiceResponse.ProccedByVendorId = "0";
                    }
                }
            }
            else
            {
                airtimeServiceResponse.ResponseStatus    = TransactionStatus.Failed.ToString();
                airtimeServiceResponse.ResponseMessage   = AirtimeValidationMessages.ErrorMessages.InvalidDataPackageId;
                airtimeServiceResponse.ProccedByVendorId = "0";
            }

            return(airtimeServiceResponse);
        }