public async Task <ActionResult> GetAsync(int id)
        {
            ProductObject response = new ProductObject();

            try
            {
                //response.EnsureSuccessStatusCode();
                //string responseBody = await response.Content.ReadAsStringAsync();
                //Above three lines can be replaced with new helper method below
                string getProductURL = baseURL + id + exclude;
                string responseBody  = await client.GetStringAsync(getProductURL);

                ProductResponseData productResponseData = JsonConvert.DeserializeObject <ProductResponseData>(responseBody);
                response.id            = id;
                response.name          = productResponseData.product.item.product_description.title;
                response.current_price = getCurrentPrice(id);
                Console.WriteLine(responseBody);
            }
            catch (HttpRequestException e)
            {
                if (e is HttpRequestException)
                {
                    Console.WriteLine("\n HTTP get Product Response Error");
                    Console.WriteLine("Message :{0} ", e.Message);
                }
            }
            return(Ok(response));
        }
        public async Task <IEnumerable <ProductResponseData> > GetAsync()
        {
            List <ProductResponseData> products = new List <ProductResponseData>();

            for (int i = 0; i < productIDs.Length; i++)
            {
                ProductResponseData product = await UpsertToDB(productIDs[i]);

                if (product != null)
                {
                    products.Add(product);
                }
            }

            return(products);
        }
        private async Task <ProductResponseData> UpsertToDB(int productid)
        {
            DatastoreDb db = DatastoreDb.Create(projectId, "ProductNamespace", datastoreClient);

            ProductResponseData productResponseData = null;

            try
            {
                string getProductURL = baseURL + productid + exclude;
                string responseBody  = await client.GetStringAsync(getProductURL);

                productResponseData = JsonConvert.DeserializeObject <ProductResponseData>(responseBody);
                Console.WriteLine(responseBody);

                string name = productid + "";
                //CurrentPrice currentPrice = new CurrentPrice();
                //currentPrice.value = productResponseData.product.price.listPrice.price;
                //currentPrice.currency_code = "USD";
                double     price      = productResponseData.product.price.listPrice.price;
                KeyFactory keyFactory = db.CreateKeyFactory(kind);
                Key        key        = keyFactory.CreateKey(name);

                var task = new Entity
                {
                    Key               = key,
                    ["productid"]     = name,
                    ["price"]         = price,
                    ["currency_code"] = "USD"
                };
                upsert(db, task);
            }
            catch (Exception e)
            {
                Console.WriteLine("\nException Caught!");
                Console.WriteLine("Message :{0} ", e.Message);
                return(null);
            }



            return(productResponseData);
        }