public async Task <IActionResult> Create([Bind("ProductID,ProductName,Description,Image,Price,CategoryID")] ProductViewModel productViewModel) { if (ModelState.IsValid) { string uniqueFileName = UploadedFile(productViewModel); Product product = new Product { ProductName = productViewModel.ProductName, Description = productViewModel.Description, Image = uniqueFileName, Price = productViewModel.Price, CategoryID = productViewModel.CategoryID, RestaurantID = productViewModel.RestaurantID, }; _context.Add(product); ViewData["Category"] = new SelectList(_context.Set <Category>(), "CategoryID", "CategoryName", product.CategoryID); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(List))); } return(View()); }
public async Task <IActionResult> Create([Bind("CategoryID,CategoryName,Description")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }