public async Task <IActionResult> AddDevice(AddDeviceActionModel model)
        {
            var tracfone = new Tracfone();
            //BYOP Eligibility
            var byopEligibilityAuthUrl = "api/service-qualification-mgmt/oauth/token?grant_type=client_credentials&scope=/service-qualification-mgmt";

            dynamic byopEligibilityAuth = await tracfone.PostAPIResponse(byopEligibilityAuthUrl, _accessToken);

            var byopEligibilityUrl  = "api/service-qualification-mgmt/v1/service-qualification";
            var byopEligibilityData = new BYOPEligibiltyData
            {
                RelatedParties = new List <RelatedParty>
                {
                    new RelatedParty
                    {
                        Party = new Party
                        {
                            PartyID         = "Approved Link",
                            LanguageAbility = "ENG",
                            PartyExtension  = new List <Extension>
                            {
                                new Extension
                                {
                                    Name  = "partyTransactionID",
                                    Value = "12345"
                                },
                                new Extension
                                {
                                    Name  = "sourceSystem",
                                    Value = "EBP"
                                }
                            }
                        },
                        RoleType = "partner"
                    }
                },
                Location = new Location
                {
                    PostalAddress = new PostalAddress
                    {
                        Zipcode = "33178"
                    }
                },
                ServiceCategory = new List <ServiceCategory>
                {
                    new ServiceCategory
                    {
                        Type  = "context",
                        Value = "BYOP_ELIGIBILITY"
                    }
                },
                ServiceSpecification = new Specification
                {
                    Brand = "CLEARWAY"
                },
                Service = new Service
                {
                    Carrier = new List <Extension>
                    {
                        new Extension
                        {
                            Name  = "carrierName",
                            Value = "VZW"
                        }
                    }
                },
                RelatedResources = new List <RelatedResource>
                {
                    new RelatedResource
                    {
                        SerialNumber = model.Serial,
                        Name         = "productSerialNumber",
                        Type         = "HANDSET"
                    }
                }
            };
            var byopEligibilityResult = "";

            for (int i = 0; i < 3; i++)
            {
                byopEligibilityResult = await tracfone.PostAPIResponse(byopEligibilityUrl, $"{byopEligibilityAuth.token_type} {byopEligibilityAuth.access_token}", byopEligibilityData);
            }
            JObject jEligibilityObj       = JObject.Parse(byopEligibilityResult);
            string  byopEligibilityStatus = jEligibilityObj["status"]["code"].ToString();

            if (byopEligibilityStatus != "200")
            {
                return(Json(byopEligibilityResult));
            }

            //BYOP Registration

            //BYOP Registration Auth
            var     byopRegistrationAuthUrl = "api/resource-mgmt/oauth/token?grant_type=client_credentials&scope=/resource-mgmt";
            dynamic byopRegistrationAuth    = await tracfone.PostAPIResponse(byopRegistrationAuthUrl, _accessToken);

            var byopRegistrationUrl  = $"api/resource-mgmt/v1/resource?client_id={_clientID}";
            var byopRegistrationData = new BYOPRegistrationData
            {
                RelatedParties = new List <RelatedParty>
                {
                    new RelatedParty
                    {
                        Party = new Party
                        {
                            PartyID         = "Approved Link",
                            LanguageAbility = "ENG",
                            PartyExtension  = new List <Extension>
                            {
                                new Extension
                                {
                                    Name  = "partyTransactionID",
                                    Value = "1231234234424"
                                },
                                new Extension
                                {
                                    Name  = "sourceSystem",
                                    Value = "EBP"
                                }
                            }
                        },
                        RoleType = "partner"
                    }
                },
                Resource = new Resource
                {
                    Location = new Location
                    {
                        PostalAddress = new PostalAddress
                        {
                            Zipcode = "33178"
                        }
                    },
                    Association = new Association
                    {
                        Role = "REGISTER"
                    },
                    ResourceSpecification = new Specification
                    {
                        Brand = "CLEARWAY"
                    },
                    PhysicalResource = new PhysicalResource
                    {
                        ResourceCategory    = "HANDSET",
                        ResourceSubCategory = "BYOP",
                        SerialNumber        = model.Serial,
                        supportingResources = new List <SupportingResource>
                        {
                            new SupportingResource
                            {
                                ResourceCategory   = "SIM_SIZE",
                                ResourceIdentifier = ""
                            },
                            new SupportingResource
                            {
                                ResourceCategory   = "SIM_CARD",
                                ResourceIdentifier = model.Sim
                            }
                        }
                    },
                    SupportingLogicalResources = new List <SupportingResource>
                    {
                        new SupportingResource
                        {
                            ResourceCategory   = "CARRIER",
                            ResourceIdentifier = "VZW"
                        }
                    }
                }
            };
            var byopRegistrationResult = await tracfone.PostAPIResponse(byopRegistrationUrl, $"{byopRegistrationAuth.token_type} {byopRegistrationAuth.access_token}", byopRegistrationData);

            JObject jRegistrationObj       = JObject.Parse(byopRegistrationResult);
            string  byopRegistrationStatus = jRegistrationObj["status"]["code"].ToString();

            if (byopRegistrationStatus != "200")
            {
                return(Json(byopRegistrationResult));
            }

            //Add Device
            var     addDeviceUrl  = $"api/customer-mgmt/addDeviceToAccount?client_id={_jwtClientID}";
            dynamic addDeviceAuth = await tracfone.GetJWTAuthorization(_username, _password, _jwtAccessToken);

            var addDeviceData = new AddDeviceData
            {
                RelatedParties = new List <RelatedParty>
                {
                    new RelatedParty
                    {
                        Party = new Party
                        {
                            PartyID         = "Approved Link",
                            LanguageAbility = "ENG",
                            PartyExtension  = new List <Extension>
                            {
                                new Extension
                                {
                                    Name  = "vendorName",
                                    Value = "Approved Link"
                                },
                                new Extension
                                {
                                    Name  = "vendorStore",
                                    Value = "1231234234424"
                                },
                                new Extension
                                {
                                    Name  = "vendorTerminal",
                                    Value = "1231234234424"
                                },
                                new Extension
                                {
                                    Name  = "sourceSystem",
                                    Value = "EBP"
                                },
                                new Extension
                                {
                                    Name  = "accountEmail",
                                    Value = _username
                                },
                                new Extension
                                {
                                    Name  = "partyTransactionID",
                                    Value = "indirect_1231234234424"
                                }
                            }
                        },
                        RoleType = "PARTNER"
                    }
                },
                CustomerAccounts = new List <CustomerAccount>
                {
                    new CustomerAccount
                    {
                        Action           = "ADD_DEVICE",
                        CustomerProducts = new List <CustomerProduct>
                        {
                            new CustomerProduct
                            {
                                Product = new Product
                                {
                                    ProductSerialNumber  = model.Serial,
                                    ProductStatus        = "ACTIVE",
                                    AccountId            = "681177314",
                                    ProductCategory      = "HANDSET",
                                    ProductSpecification = new Specification
                                    {
                                        Brand = "CLEARWAY"
                                    }
                                }
                            }
                        }
                    }
                }
            };
            var addDeviceResult = await tracfone.PostAPIResponse(addDeviceUrl, $"Bearer {addDeviceAuth.access_token}", addDeviceData);

            return(Json(addDeviceResult));
        }
        public async Task <IActionResult> DeleteDevice(DeleteActionModel model)
        {
            var tracfone = new Tracfone();

            var url  = $"api/customer-mgmt/deleteDeviceAccount?client_id={_jwtClientID}";
            var auth = await tracfone.GetJWTAuthorization(_username, _password, _jwtAccessToken);

            var data = new AddDeviceData
            {
                RelatedParties = new List <RelatedParty>
                {
                    new RelatedParty
                    {
                        Party = new Party
                        {
                            PartyID         = "",
                            LanguageAbility = "ENG",
                            PartyExtension  = new List <Extension>
                            {
                                new Extension
                                {
                                    Name  = "vendorName",
                                    Value = "1231234234424"
                                },
                                new Extension
                                {
                                    Name  = "vendorStore",
                                    Value = "1231234234424"
                                },
                                new Extension
                                {
                                    Name  = "vendorTerminal",
                                    Value = "1231234234424"
                                },
                                new Extension
                                {
                                    Name  = "sourceSystem",
                                    Value = "EBP"
                                },
                                new Extension
                                {
                                    Name  = "accountEmail",
                                    Value = _username
                                },
                                new Extension
                                {
                                    Name  = "partyTransactionID",
                                    Value = "indirect_1231234234424"
                                }
                            }
                        },
                        RoleType = "partner"
                    }
                },
                CustomerAccounts = new List <CustomerAccount>
                {
                    new CustomerAccount
                    {
                        Action           = "DELETE_DEVICE",
                        CustomerProducts = new List <CustomerProduct>
                        {
                            new CustomerProduct
                            {
                                Product = new Product
                                {
                                    ProductSerialNumber  = model.Serial,
                                    ProductStatus        = "ACTIVE",
                                    AccountId            = "681177314",
                                    ProductCategory      = "HANDSET",
                                    ProductSpecification = new Specification
                                    {
                                        Brand = "CLEARWAY"
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var result = await tracfone.PostAPIResponse(url, $"Bearer {auth.access_token}", data);

            return(Json(result));
        }