Exemplo n.º 1
0
        public AjaxResponse SaveMenusModel(MenusInput model)
        {
            long resId;

            var isRepeat = IsPermissionRepeat(model.PermissionName, model.ID);

            if (isRepeat)
            {
                throw new UserFriendlyException("菜单授权名称重复", "您设置的授权名称" + model.PermissionName + "重复!");
            }

            if (model.ID == null)
            {
                SysMenus modelInput = model.MapTo <SysMenus>();
                resId = _sysMenusRepository.InsertAndGetId(modelInput);
            }
            else
            {
                MenusUpdata modelInput = model.MapTo <MenusUpdata>();
                long        id         = Convert.ToInt64(model.ID);
                //获取需要更新的数据
                SysMenus data = _sysMenusRepository.Get(id);
                //映射需要修改的数据对象
                SysMenus m = ObjectMapper.Map(modelInput, data);
                //修改动作明细数据
                List <SysMenuAction> menuActionList = model.SysMenuActions.MapTo <List <SysMenuAction> >();
                if (menuActionList != null && menuActionList.Any())
                {
                    _sysMenuActionRepository.UpdataMenusAction(menuActionList, id);
                }
                else
                {
                    //如果保存时候未发现有设置的动作列表就清除掉原有的动作
                    _sysMenuActionRepository.DelMenusAction(id);
                }
                //修改菜单主数据
                var resModel = _sysMenusRepository.Update(m);
                resId = resModel.Id;
            }

            //清除模块缓存
            _cacheManagerExtens.RemoveMenuActionPermissionCache();

            //重置初始菜单以及授权
            _navigationMenusExt.UpNavigationMenusProvider(model.MapTo <SysMenus>());

            return(new AjaxResponse {
                Success = true, Result = new { id = resId }
            });
        }
Exemplo n.º 2
0
        public void DelMenusModel(long id)
        {
            var isParent = _sysMenusRepository.GetAll().Where(w => w.ParentID == id);

            if (isParent.Any())
            {
                throw new UserFriendlyException("删除菜单失败", "请先删除当前菜单的子菜单!");
            }
            //删除模块明细
            _sysMenuActionRepository.DelMenusAction(id);
            //删除模块
            _sysMenusRepository.Delete(id);
            //提交操作后在进行缓存刷新
            _unitOfWorkManager.Current.SaveChanges();
            //清除模块缓存
            _cacheManagerExtens.RemoveMenuActionPermissionCache();
            //重置初始菜单以及授权
            _navigationMenusExt.UpNavigationMenusProvider();
        }