Exemple #1
0
        public IActionResult NewCategory(NewCategoryIndexViewModel viewModel)
        {
            if (DbContext.Categories.Any(c => c.CategoryName == viewModel.Name))
            {
                ModelState.AddModelError("Name", "Category already exist");
            }

            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var dbCat = new Category();

            DbContext.Add(dbCat);
            dbCat.CategoryName = viewModel.Name;
            dbCat.Description  = viewModel.Description;
            DbContext.SaveChanges();

            return(RedirectToAction("ListCategories"));
        }
Exemple #2
0
        public IActionResult NewCategory()
        {
            var viewModel = new NewCategoryIndexViewModel();

            return(View(viewModel));
        }