private void ExecuteAddCategoryCommand(object obj)
        {
            var newCategory = new CategoryModel();
            var view        = new NewCategoryView(newCategory);
            var showDialog  = view.ShowDialog();

            if (showDialog != null && showDialog.Value)
            {
                Categories.Add(newCategory);
            }
        }
Exemple #2
0
        public IActionResult Index()
        {
            if (HttpContext.Session.GetInt32("InvalidEntry") == 1)
            {
                HttpContext.Session.SetInt32("InvalidEntry", 0);
                ModelState.AddModelError("Category.Name", "Invalid Entry");
            }

            NewCategoryView NewCatView = new NewCategoryView();

            NewCatView.Categories = dbContext.Categories.ToList();

            return(View(NewCatView));
        }
Exemple #3
0
        public IActionResult NewCategory(NewCategoryView newCategory)
        {
            if (ModelState.IsValid)
            {
                dbContext.Categories.Add(newCategory.Category);
                dbContext.SaveChanges();

                Category lastAddedCategory = dbContext.Categories.LastOrDefault();

                return(RedirectToAction("Index")); //, new {id = lastAddedCategory.CategoryID}
            }
            else
            {
                HttpContext.Session.SetInt32("InvalidEntry", 1);
                return(RedirectToAction("Index"));
            }
        }