public async Task<ActionResult> UpdateProduct(Product prodToEdit, HttpPostedFileBase file1, HttpPostedFileBase file2, HttpPostedFileBase file3, HttpPostedFileBase file4, HttpPostedFileBase file5)
        {
            Result<ValidationResult_OSC> result = new Result<ValidationResult_OSC>();

            using (var client = new HttpClient())
            {
                string url = System.Configuration.ConfigurationManager.AppSettings["ProductAPI"];
                client.BaseAddress = new Uri(url);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                prodToEdit.CreatedOn = DateTime.Now;
                HttpResponseMessage response = await client.PutAsJsonAsync("api/Product/", prodToEdit);
                if (response.IsSuccessStatusCode)
                {
                    result = await response.Content.ReadAsAsync<Result<ValidationResult_OSC>>();
                    if (result.Success == true)
                    {
                        return Json(result, JsonRequestBehavior.AllowGet);
                    }
                }

            }
            return Json(result, JsonRequestBehavior.AllowGet);
        }
        public void AddTempData()
        {
            ProductCategory cat1 = new ProductCategory()
            {
                ID = 1,
                Category = "Men & Womens Clothes",
                ParentCategoryID = 1,
                IsActive = true,
                CreatedOn = DateTime.Now,
                UpdatedOn = DateTime.Now,
                CreatedByUserID = 1,
                UpdatedByUserID = 2
            };
            ProductCategory cat2 = new ProductCategory()
            {
                ID = 2,
                Category = "footwear",
                ParentCategoryID = 1,
                IsActive = true,
                CreatedOn = DateTime.Now,
                UpdatedOn = DateTime.Now,
                CreatedByUserID = 1,
                UpdatedByUserID = 2
            };
            ProductCategory cat3 = new ProductCategory()
            {
                ID = 3,
                Category = "watches",
                ParentCategoryID = 1,
                IsActive = true,
                CreatedOn = DateTime.Now,
                UpdatedOn = DateTime.Now,
                CreatedByUserID = 1,
                UpdatedByUserID = 2
            };
            ProductCategory cat4 = new ProductCategory()
            {
                ID = 4,
                Category = "fashion",
                ParentCategoryID = 1,
                IsActive = true,
                CreatedOn = DateTime.Now,
                UpdatedOn = DateTime.Now,
                CreatedByUserID = 1,
                UpdatedByUserID = 2
            };
            ProductCategory cat5 = new ProductCategory()
            {
                ID = 5,
                Category = "Books",
                ParentCategoryID = 1,
                IsActive = true,
                CreatedOn = DateTime.Now,
                UpdatedOn = DateTime.Now,
                CreatedByUserID = 1,
                UpdatedByUserID = 2
            };

            Product prod1 = new Product()
            {
                ID = 1,
                ProductCode = "2344",
                ProductName = "Revolution 2020",
                ProductDescription = "test",
                CategoryID = 5,
                Brand = "..Publications",
                Model = "test",
                UnitPrice = 500,
                SKU = "some keeping unit",
                CurrentStock = 478,
                IsActive = true,
                CreatedOn = DateTime.Now,
                UpdatedOn = DateTime.Now,
                CreatedByUserID = 1,
                UpdatedByUserID = 2,
                //ImageThumbNail=
                //ImageIndex
                //ImageOthers

            };
            Product prod2 = new Product()
            {
                ID = 2,
                ProductCode = "2344",
                ProductName = "Filmfair maghzine",
                ProductDescription = "test",
                CategoryID = 4,
                Brand = "..Publications",
                Model = "test",
                UnitPrice = 500,
                SKU = "some keeping unit",
                CurrentStock = 478,
                IsActive = true,
                CreatedOn = DateTime.Now,
                UpdatedOn = DateTime.Now,
                CreatedByUserID = 1,
                UpdatedByUserID = 2,
                //ImageThumbNail=
                //ImageIndex
                //ImageOthers

            };
            Product prod3 = new Product()
            {
                ID = 3,
                ProductCode = "2344",
                ProductName = "Rado",
                ProductDescription = "test",
                CategoryID = 3,
                Brand = "..Publications",
                Model = "test",
                UnitPrice = 500,
                SKU = "some keeping unit",
                CurrentStock = 478,
                IsActive = true,
                CreatedOn = DateTime.Now,
                UpdatedOn = DateTime.Now,
                CreatedByUserID = 1,
                UpdatedByUserID = 2,
                //ImageThumbNail=
                //ImageIndex
                //ImageOthers

            };
            Product prod4 = new Product()
            {
                ID = 4,
                ProductCode = "2344",
                ProductName = "bata",
                ProductDescription = "test",
                CategoryID = 2,
                Brand = "..Publications",
                Model = "test",
                UnitPrice = 500,
                SKU = "some keeping unit",
                CurrentStock = 478,
                IsActive = true,
                CreatedOn = DateTime.Now,
                UpdatedOn = DateTime.Now,
                CreatedByUserID = 1,
                UpdatedByUserID = 2,
                //ImageThumbNail=
                //ImageIndex
                //ImageOthers

            };
            Product prod5 = new Product()
            {
                ID = 5,
                ProductCode = "2344",
                ProductName = "Pepe Jeans",
                ProductDescription = "test",
                CategoryID = 1,
                Brand = "..Publications",
                Model = "test",
                UnitPrice = 500,
                SKU = "some keeping unit",
                CurrentStock = 478,
                IsActive = true,
                CreatedOn = DateTime.Now,
                UpdatedOn = DateTime.Now,
                CreatedByUserID = 1,
                UpdatedByUserID = 2,
                //ImageThumbNail=
                //ImageIndex
                //ImageOthers

            };

            Product prod6 = new Product()
            {
                ID = 6,
                ProductCode = "2344",
                ProductName = "Lee Cooper",
                ProductDescription = "test",
                CategoryID = 2,
                Brand = "..Publications",
                Model = "test",
                UnitPrice = 500,
                SKU = "some keeping unit",
                CurrentStock = 478,
                IsActive = true,
                CreatedOn = DateTime.Now,
                UpdatedOn = DateTime.Now,
                CreatedByUserID = 1,
                UpdatedByUserID = 2,
                //ImageThumbNail=
                //ImageIndex
                //ImageOthers

            };

            Product prod7 = new Product()
            {
                ID = 7,
                ProductCode = "2344",
                ProductName = "Red Chief",
                ProductDescription = "test",
                CategoryID = 2,
                Brand = "..Publications",
                Model = "test",
                UnitPrice = 500,
                SKU = "some keeping unit",
                CurrentStock = 478,
                IsActive = true,
                CreatedOn = DateTime.Now,
                UpdatedOn = DateTime.Now,
                CreatedByUserID = 1,
                UpdatedByUserID = 2,
                //ImageThumbNail=
                //ImageIndex
                //ImageOthers

            };
            Product prod8 = new Product()
            {
                ID = 8,
                ProductCode = "2344",
                ProductName = "Goggles",
                ProductDescription = "test",
                CategoryID = 4,
                Brand = "..Publications",
                Model = "test",
                UnitPrice = 500,
                SKU = "some keeping unit",
                CurrentStock = 478,
                IsActive = true,
                CreatedOn = DateTime.Now,
                UpdatedOn = DateTime.Now,
                CreatedByUserID = 1,
                UpdatedByUserID = 2,
                //ImageThumbNail=
                //ImageIndex
                //ImageOthers

            };

            prodcatList.Add(cat1);
            prodcatList.Add(cat2);
            prodcatList.Add(cat3);
            prodcatList.Add(cat4);
            prodcatList.Add(cat5);

            prodList.Add(prod1);
            prodList.Add(prod2);
            prodList.Add(prod3);
            prodList.Add(prod4);
            prodList.Add(prod5);
            prodList.Add(prod6);
            prodList.Add(prod7);
            prodList.Add(prod8);

            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
            ViewBag.ProductCategories = prodcatList;
            ViewBag.Products = prodList;
        }
        public async Task<ActionResult> InsertProduct(Product product, HttpPostedFileBase file1, HttpPostedFileBase file2, HttpPostedFileBase file3, HttpPostedFileBase file4, HttpPostedFileBase file5)
        {
            Result<ValidationResult_OSC> result = new Result<ValidationResult_OSC>();
            int productIDAfterInsertProduct;
            #region PRODUCT INSERT DOUBLE VALIDATION
            if (product == null)
            {
                result.Success = false;
                result.Message = "Can not insert Empty Product!";
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            #endregion
            #region IMAGE INSERT VALIDATION

            List<HttpPostedFileBase> prodImageList = new List<HttpPostedFileBase>();
            #region file list
            if (file1 != null)
            {
                prodImageList.Add(file1);
            }
            if (file2 != null)
            {
                prodImageList.Add(file2);
            }
            if (file3 != null)
            {
                prodImageList.Add(file3);
            }
            if (file4 != null)
            {
                prodImageList.Add(file4);
            }
            if (file5 != null)
            {
                prodImageList.Add(file5);
            }
            #endregion

            product.ProductImages = prodImageList;


            if (product.ProductImages.Count == 0)
            {
                result.Success = false;
                result.Message = "Please Upload An Image to Proceed!";
                return Json(result, JsonRequestBehavior.AllowGet);
            }

            #endregion
            #region PRODUCT INSERT AND IMAGE INSERT

            using (var client = new HttpClient())
            {
                string url = System.Configuration.ConfigurationManager.AppSettings["ProductAPI"];
                client.BaseAddress = new Uri(url);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                product.CreatedOn = DateTime.Now;
                HttpResponseMessage response = await client.PostAsJsonAsync("api/Product/InsertProduct", product);
                if (response.IsSuccessStatusCode)
                {
                    result = await response.Content.ReadAsAsync<Result<ValidationResult_OSC>>();
                    if (result.Success == false)
                    {
                        return Json(result, JsonRequestBehavior.AllowGet);

                    }
                    productIDAfterInsertProduct = Int32.Parse(result.returnValue);


                    //save image to azure blob
                    SaveImagesToAzureBlob saveImage = new SaveImagesToAzureBlob();
                    var ImageInsertedToBothDBAndAzure = await saveImage.SaveImageToBlob(product.ProductImages, productIDAfterInsertProduct);

                    if (ImageInsertedToBothDBAndAzure)
                        return Json(result, JsonRequestBehavior.AllowGet);
                    else
                    {
                        result.Success = false;
                        result.Message = "Image not saved";
                        return Json(result, JsonRequestBehavior.AllowGet);
                    }
                }
                else
                    return Json(result, JsonRequestBehavior.AllowGet);

            }
            #endregion
        }