Example #1
0
        public IActionResult AddCategoryPage()
        {
            AddCategoryPageW vMod = new AddCategoryPageW();

            vMod.ListOfCategories = dbContext.Categories
                                    .Include(c => c.ListOfProducts)
                                    .ToList();
            return(View(vMod));
        }
Example #2
0
        public IActionResult AddCategory(AddCategoryPageW formData)
        {
            AddCategoryPageW vMod = new AddCategoryPageW();

            vMod.ListOfCategories = dbContext.Categories
                                    .Include(c => c.ListOfProducts)
                                    .ToList();
            if (ModelState.IsValid)
            {
                if (dbContext.Categories.Any(b => b.Name == formData.Category.Name))
                {
                    ModelState.AddModelError("Category.Name", "You cannot create a Category with the same name as an existing Category.");

                    return(View("AddCategoryPage", vMod));
                }
                dbContext.Categories.Add(formData.Category);
                dbContext.SaveChanges();

                return(RedirectToAction("AddProductPage"));
            }
            return(View("AddCategoryPage", vMod));
        }