Пример #1
0
        public IActionResult Create()
        {
            ProdCatViewModel ProdCatVM = new ProdCatViewModel
            {
                Categories = categoryRepository.GetAll().ToList()
            };

            return(View("productForm", ProdCatVM));
        }
Пример #2
0
        public IActionResult Edit(int id)

        {
            ProdCatViewModel ProdCatVM = new ProdCatViewModel
            {
                Categories = categoryRepository.GetAll().ToList(),
                Product    = productRepository.GetById(id)
            };

            return(View("productForm", ProdCatVM));
        }
Пример #3
0
        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));
        }
Пример #4
0
        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));
        }
Пример #5
0
        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));
        }