public async Task <bool> SyncProduct(string shopname, string token, string serverurl)
        {
            bool response = true;

            try
            {
                string             shopifyurl = $"https://{shopname}.myshopify.com/";
                var                client     = new HttpClient();
                ProductDetailModel model      = new ProductDetailModel();
                model.shopifyurl = shopifyurl;
                model.token      = token;
                List <Product> products = await GetAllProducts(model);

                List <ProductReturnModel> productReturns = await GetProductReturnModel(products, shopname);

                string apiUrl2   = $"{serverurl}/api/AddShopifyProducts";
                string json      = JsonConvert.SerializeObject(productReturns);
                var    response2 = client.PostAsJsonAsync(apiUrl2, productReturns).Result;
                response2.EnsureSuccessStatusCode();
                string responseBody1 = await response2.Content.ReadAsStringAsync();

                var readString = JObject.Parse(responseBody1)["status"];
                response = Convert.ToBoolean(readString.ToString());
            }
            catch (Exception)
            {
                throw;
            }
            return(response);
        }
        public async Task <Product> GetProduct(ProductDetailModel model)
        {
            Product product = new Product();
            string  msg;

            try
            {
                var allProducts = new List <Product>();
                var service     = new ProductService(model.shopifyurl, model.token);
                product = await service.GetAsync(Convert.ToInt64(model.productId));

                var mservice = new MetaFieldService(model.shopifyurl, model.token);
                foreach (var vgt in product.Variants)
                {
                    var vmetafields = await mservice.ListAsync(Convert.ToInt64(vgt.Id), "variants");

                    vgt.Metafields = vmetafields.Items;
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message.ToString();
            }
            return(product);
        }
        public async Task <List <Product> > GetAllProducts(ProductDetailModel model)
        {
            Product        product  = new Product();
            List <Product> Products = new List <Product>();
            string         msg;

            try
            {
                var allProducts = new List <Product>();
                var service     = new ProductService(model.shopifyurl, model.token);
                var page        = await service.ListAsync(new ProductListFilter
                {
                    Limit = 250,
                });

                //allProducts.AddRange(page.Items);
                while (true)
                {
                    allProducts.AddRange(page.Items);

                    if (!page.HasNextPage)
                    {
                        break;
                    }

                    page = await service.ListAsync(page.GetNextPageFilter());
                }
                Products = allProducts;
                var mservice = new MetaFieldService(model.shopifyurl, model.token);
                foreach (var item in Products)
                {
                    var metafields = await mservice.ListAsync(Convert.ToInt64(item.Id), "products");

                    string value = JsonConvert.SerializeObject(metafields.Items);
                    item.Metafields = metafields.Items;
                    foreach (var vgt in item.Variants)
                    {
                        var vmetafields = await mservice.ListAsync(Convert.ToInt64(vgt.Id), "variants");

                        vgt.Metafields = vmetafields.Items;
                    }
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message.ToString();
            }
            return(Products);
        }