public async Task <IActionResult> EditProduct(int productId) { var vm = new EditorProductVM { Product = await db.Products.FindAsync(productId), Categories = await db.Categories .Include(c => c.SubCategories) .ToListAsync() }; return(View(vm)); }
public async Task <ActionResult> EditProduct(Product product, string Price_string, string Weight_string, string Volume_string, string IsEdit) { var path = await UploadImage(product.ImagePath); if (String.IsNullOrEmpty(path)) { if (String.IsNullOrEmpty(product.ImagePath)) { product.ImagePath = $"/Products/Images/{product.Name}.jpg"; } } else { product.ImagePath = path; } if (Volume_string != null) { if (Volume_string.Contains('.')) { Volume_string = Volume_string.Replace('.', ','); } } product.Price = Convert.ToDouble(Price_string); product.Weight = Convert.ToDouble(Weight_string); Console.WriteLine(Volume_string); product.Volume = Convert.ToDouble(Volume_string); if (Convert.ToBoolean(IsEdit)) { db.Products.Update(product); } else { await db.Products.AddAsync(product); } await db.SaveChangesAsync(); //return View("~/Views/Home/Index.cshtml"); var vm = new EditorProductVM { Categories = await db.Categories .Include(c => c.SubCategories) .ToListAsync() }; return(View("~/Views/Editor/EditProduct.cshtml", vm)); }