public ActionResult UpdateProduct(AddOrUpdateProductModel addOrUpdateProductModel, string filter)
 {
     if (ModelState.IsValid)
     {
         if (addOrUpdateProductModel.Images.FirstOrDefault() != null)
         {
             string folderPath = Server.MapPath($"~/Content/image/product/{addOrUpdateProductModel.Product.Id}");
             Directory.CreateDirectory(folderPath);
             foreach (var image in addOrUpdateProductModel.Images)
             {
                 string imagePaht = Server.MapPath($"~/Content/image/product/{addOrUpdateProductModel.Product.Id}/{image.FileName}");
                 image.SaveAs(imagePaht);
                 ir.AddOrUpdate(new Image()
                 {
                     ProductId = addOrUpdateProductModel.Product.Id, Paht = $"/Content/image/product/{addOrUpdateProductModel.Product.Id}/{image.FileName}"
                 });
             }
         }
         pr.AddOrUpdate(addOrUpdateProductModel.Product);
         return(RedirectToAction("ProductList", new { filter = filter }));
     }
     ViewBag.MainCat = new SelectList(mcr.SelectAll(), "Id", "Name", scr.SelectById(addOrUpdateProductModel.Product.SubCategoryId).MainCategoryId);
     ViewBag.SubCat  = new SelectList(mcr.SelectById(scr.SelectById(addOrUpdateProductModel.Product.SubCategoryId).MainCategoryId).SubCategories, "Id", "Name", ViewBag.Filter = filter);
     return(View(addOrUpdateProductModel));
 }
 public ActionResult SubCategoryAddOrUpdate(string CategoryName, string MainCatId, string id)
 {
     if (id == null)
     {
         if (!String.IsNullOrWhiteSpace(CategoryName))
         {
             var subCat = new SubCategory()
             {
                 Name = CategoryName, MainCategoryId = MainCatId
             };
             scr.AddOrUpdate(subCat);
         }
     }
     else
     {
         if (!String.IsNullOrWhiteSpace(CategoryName))
         {
             var subCat = scr.SelectById(id);
             subCat.Name = CategoryName;
             scr.AddOrUpdate(subCat);
         }
     }
     return(RedirectToAction("Categories"));
 }