Esempio n. 1
0
        public async Task <IActionResult> Create(AdminCategoryCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                await this.adminCategoryService.CreateAsync(model.Name);

                return(RedirectToAction(nameof(Index)));
            }

            return(this.View(model));
        }
        public ActionResult CreateCategory(AdminCategoryCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                db.KL_Categories.Add(new KL_Category {
                    Name          = model.Name,
                    KL_CategoryId = model.ParentId
                });
                db.SaveChanges();

                return(RedirectToAction("Categories"));
            }

            return(RedirectToAction("CreateCategory", new { msg = "Error in creating." }));
        }
        public ActionResult CreateCategory(string id = "")
        {
            var allCategories = db.KL_Categories
                                .Include(m => m.ChildCategories)
                                .OrderBy(m => m.Name)
                                .ToList();



            var model = new AdminCategoryCreateViewModel {
                Categories = new Dictionary <string, int>(),
                ParentId   = 0
            };

            foreach (var cat in allCategories)
            {
                model.Categories.Add(cat.Name, cat.Id);
            }

            ViewBag.Message = id;
            return(View(model));
        }