Ejemplo n.º 1
0
        public ActionResult CreateMainMenu( MainMenu model)
        {
            if (ModelState.IsValid)
            {
                model.IsMenu = true;
                try
                {
                    if (_categoryService.GetCategory(model.Code) == null)
                    {
                        MainCategory mainCategory = _categoryService.GetMainCategories().Where(m => m.Code == (int)MainCategoryType.Menu).First();
                        model.ParentCategoryCode = mainCategory.Code;
                        _categoryService.CreateCategory(model);
                        _categoryService.SaveCategory();
                        return RedirectToAction("Index");
                    }
                    else
                    {
                        ModelState.AddModelError("Code", ErrorMessages.CATEGORYCODE_EXIST);
                    }

                }
                catch(Exception e)
                {
                    ModelState.AddModelError("", e);
                }

            }
            return View(model);
        }
Ejemplo n.º 2
0
        public IEnumerable<SubCategory> GetSubMenus(ApplicationUser user, MainMenu mainMenu)
        {
            List<SubCategory> subMenus = new List<SubCategory>();

            if(null != user.CanAccessCategories)
            {
                // get all submenus of mainmenu
                List<SubCategory> subAllMenus = mainMenu.GetSubMenus().ToList();
                // all submenus have grant permission to user
                List<SubMenu> permissionSubMenus = user.CanAccessCategories.ToList();

                foreach (var subMenu in subAllMenus)
                {
                    if (permissionSubMenus.Contains(subMenu))
                    {
                        subMenus.Add(subMenu);
                    }
                }
            }

            return subMenus;
        }