public ActionResult Authorization(int id, int[] menuids)
        {
            if (ModelState.IsValid)
            {
                var roleAuthorizationInput = new RoleAuthorizationInput {
                    Id    = id,
                    Menus = new List <Menu>()
                };
                if (menuids != null)
                {
                    foreach (var menuid in menuids)
                    {
                        roleAuthorizationInput.Menus.Add(new Menu {
                            Id = menuid
                        });
                    }
                }

                _roleService.SetAuthorization(roleAuthorizationInput);
                ViewBag.Success = "success";
            }
            var roleDto = _roleService.GetAndMenu(id);
            var menus   = _menuService.GetAll();

            return(View(new RoleAuthorizationOutput {
                RoleDto = roleDto, MenuDtos = menus
            }));
        }
示例#2
0
        public void SetAuthorization(RoleAuthorizationInput input)
        {
            Logger.Info($"角色授权");
            var role = _roleRepository.GetAndMenu(input.Id);

            role.Menus = new List <Core.System.Menu>();
            if (input.Menus.Count > 0)
            {
                input.Menus.ForEach(m => {
                    role.Menus.Add(_menuService.GetMenu(m.Id));
                });
            }
        }