public IActionResult Edit(ProductsUpdate model)
        {
            var files = HttpContext.Request.Form.Files;

            foreach (var Image in files)
            {
                if (Image != null && Image.Length > 0)
                {
                    var file = Image;
                    using (ProductDBContext dbContext = new ProductDBContext())
                    {
                        MemoryStream ms = new MemoryStream();
                        file.OpenReadStream().CopyTo(ms);


                        Models.Products.ProductsCreate imageEntity = new Models.Products.ProductsCreate()
                        {
                            Data = Convert.ToBase64String(ms.ToArray()),
                        };
                        datamax = imageEntity.Data;
                    }
                }
            }
            model.Data = datamax;
            var updateResult   = false;
            var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://localhost:44354/api/Products/update");

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "PUT";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                var json = JsonConvert.SerializeObject(model);

                streamWriter.Write(json);
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                updateResult = bool.Parse(result);
            }
            if (updateResult)
            {
                TempData["Message"] = "User has been update successfully";
            }
            ViewBag.units        = unit.GetUnits();
            ViewBag.ProductTypes = productType.GetProductTypes();
            return(RedirectToAction("Index", "Products"));
        }
        public IActionResult Create(ProductsCreate model)
        {
            var files = HttpContext.Request.Form.Files;

            foreach (var Image in files)
            {
                if (Image != null && Image.Length > 0)
                {
                    var file = Image;
                    using (ProductDBContext dbContext = new ProductDBContext())
                    {
                        MemoryStream ms = new MemoryStream();
                        file.OpenReadStream().CopyTo(ms);

                        //System.Drawing.Image image = System.Drawing.Image.FromStream(ms);

                        Models.Products.ProductsCreate imageEntity = new Models.Products.ProductsCreate()
                        {
                            Data = Convert.ToBase64String(ms.ToArray()),
                        };
                        datamax = imageEntity.Data;
                    }
                }
            }
            model.Data = datamax;
            var createResult   = false;
            var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://localhost:44354/api/Products/add");

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                var json = JsonConvert.SerializeObject(model);

                streamWriter.Write(json);
            }

            if (ModelState.IsValid)
            {
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                    createResult = bool.Parse(result);
                }
                if (createResult)
                {
                    TempData["Message"] = model.Name + " đã được thêm";
                }
                ViewBag.units        = unit.GetUnits();
                ViewBag.ProductTypes = productType.GetProductTypes();
                ModelState.Clear();
                return(View(new ProductsCreate()
                {
                }));
            }

            TempData["Success"]  = null;
            ViewBag.units        = unit.GetUnits();
            ViewBag.ProductTypes = productType.GetProductTypes();
            return(View());
        }