Example #1
0
        public bool AddProduct(Product product)
        {
            bool productAdded = false;
            var prod = new Product();
            prod.ProductId = product.ProductId;
            prod.ProductName = product.ProductName;
            prod.UnitPrice = product.UnitPrice;

            using (HttpClient httpClient = new HttpClient())
            {
                httpClient.BaseAddress = new Uri("https://microsoft-apiappc2c97ea690dc4a59ab2bc747063c4387.azurewebsites.net/");
                var url = "api/Products";
                var response = httpClient.PostAsJsonAsync(url, prod).Result;
                if (response.IsSuccessStatusCode)
                {
                    productAdded = true;
                }
            }
            return productAdded;
        }
 public async Task<ActionResult> AddProduct(string productName, string unitPrice)
 {
     Product prod = new Product();
     prod.ProductId = Guid.NewGuid().ToString();
     prod.ProductName = productName;
     decimal price;
     decimal.TryParse(unitPrice, out price);
     prod.UnitPrice = price;
     await azureDocDBHelper.AddDocument(prod, "Products");
     return View("Products");
 }
        public async Task<ActionResult> AddProduct(string productName, string unitPrice)
        {
            Product prod = new Product();
            prod.ProductId = new Guid().ToString();
            prod.ProductName = productName;
            decimal price;
            decimal.TryParse(unitPrice, out price);
            prod.UnitPrice = price;
            await azureDocDBHelper.AddDocument(prod, "Products");

            List<Product> lstProducts;
            lstProducts = await azureDocDBHelper.GetProducts();
            
            string value = JsonConvert.SerializeObject(lstProducts);
            cache.StringSet("Products", value);
            return View("Products", lstProducts);
        }
        public async Task<ActionResult> AddProduct(string productName, string unitPrice)
        {
            Product prod = new Product();
            prod.ProductId = Guid.NewGuid().ToString();
            prod.ProductName = productName;
            decimal price;
            decimal.TryParse(unitPrice, out price);
            prod.UnitPrice = price;
            restHelper.AddProduct(prod);

            List<Product> lstProducts;
            lstProducts = await restHelper.GetAllProducts();
            
            string value = JsonConvert.SerializeObject(lstProducts);
            return View("Products", lstProducts);
        }