public IActionResult Edit(int id)
        {
            var balo = baloRepository.Get(id);

            if (balo == null)
            {
                ViewBag.Id = id;
                return(View("~/Views/Error/ProductNotFound.cshtml"));
            }
            if (balo != null)
            {
                var edit = new EditViewHome()
                {
                    Id          = balo.BaloId,
                    BaloName    = balo.BaloName,
                    Trademark   = balo.Trademark,
                    Size        = balo.Size,
                    Material    = balo.Material,
                    Description = balo.Description,
                    Price       = balo.Price,
                    CategoryId  = balo.CategoryId,
                    Color       = balo.Color,
                    Sale        = balo.Sale,
                    AvatarPath  = balo.Image
                };
                ViewBag.Categories = GetCategories();
                return(View(edit));
            }
            return(View());
        }
 public IActionResult Edit(EditViewHome model)
 {
     if (ModelState.IsValid)
     {
         var balo = new Balo()
         {
             BaloId      = model.Id,
             BaloName    = model.BaloName,
             Trademark   = model.Trademark,
             Size        = model.Size,
             Material    = model.Material,
             Description = model.Description,
             Price       = model.Price,
             CategoryId  = model.CategoryId,
             Color       = model.Color,
             Sale        = model.Sale,
             KeySearch   = $"{model.BaloName.ToLower()} {model.Description.ToLower()} {model.Trademark.ToLower()}" +
                           $" {categoryRepository.Get(model.CategoryId).CategoryName.ToLower()}"
         };
         var fileName = string.Empty;
         if (model.Image != null)
         {
             string uploadFolder = Path.Combine(webHostEnvironment.WebRootPath, "images/balos");
             fileName = $"{Guid.NewGuid()}_{model.Image.FileName}";
             var filePath = Path.Combine(uploadFolder, fileName);
             using (var fs = new FileStream(filePath, FileMode.Create))
             {
                 model.Image.CopyTo(fs);
             }
             balo.Image = fileName;
             if (!string.IsNullOrEmpty(model.AvatarPath))
             {
                 string delFile = Path.Combine(webHostEnvironment.WebRootPath,
                                               "images/balos", model.AvatarPath);
                 System.IO.File.Delete(delFile);
             }
         }
         else
         {
             fileName = model.AvatarPath;
         }
         balo.Image = fileName;
         var editEmp = baloRepository.Edit(balo);
         if (editEmp != null)
         {
             return(RedirectToAction("Index", "ProductsManage"));
         }
     }
     return(View());
 }