public IActionResult Create() { ProdCatViewModel ProdCatVM = new ProdCatViewModel { Categories = categoryRepository.GetAll().ToList() }; return(View("productForm", ProdCatVM)); }
public IActionResult Edit(int id) { ProdCatViewModel ProdCatVM = new ProdCatViewModel { Categories = categoryRepository.GetAll().ToList(), Product = productRepository.GetById(id) }; return(View("productForm", ProdCatVM)); }
public IActionResult Details(int id) { var prod = productRepository.GetById(id); ProdCatViewModel DetailsProdCatVM = new ProdCatViewModel { Product = prod, Categories = categoryRepository.GetAll().ToList(), Products = productRepository.GetAll().Where(e => e.Category.Id == prod.Category.Id).ToList() }; return(View("Detail", DetailsProdCatVM)); }
public IActionResult Create(Product product) { if (ModelState.IsValid) { product.VendorId = User.FindFirstValue(ClaimTypes.NameIdentifier); productRepository.Add(product); TempData["Message"] = "Product Added successfully"; return(RedirectToAction(nameof(Index))); } ProdCatViewModel ProdCatVM = new ProdCatViewModel { Categories = categoryRepository.GetAll().ToList() }; return(View("productForm", ProdCatVM)); }
public IActionResult Edit([FromRoute] int id, Product product) { if (id != product.Id) { NotFound(); } if (ModelState.IsValid) { productRepository.Update(product); TempData["Message"] = "Product edited successfully"; return(RedirectToAction(nameof(Index))); } ProdCatViewModel ProdCatVM = new ProdCatViewModel { Categories = categoryRepository.GetAll().ToList(), Product = product }; return(View("productForm", ProdCatVM)); }