示例#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 }
            });
        }
示例#2
0
        public AjaxResponse SaveMenusModel(MenusInput model)
        {
            long resId;

            #region 验证
            MenuData menuData = ObjectMapper.Map <MenuData>(model);
            var      isRepeat = IsPermissionRepeat(menuData);
            if (isRepeat)
            {
                throw new UserFriendlyException("菜单授权名称重复", "您设置的授权名称" + model.PermissionName + "重复!");
            }
            #endregion
            if (model.Id == null)
            {
                #region 新增
                SysMenus modelInput = ObjectMapper.Map <SysMenus>(model);
                resId = _sysMenusRepository.InsertAndGetId(modelInput);
                #endregion
            }
            else
            {
                #region 编辑
                long id = Convert.ToInt64(model.Id);
                //获取需要更新的数据
                SysMenus data = _sysMenusRepository.Get(id);
                //映射需要修改的数据对象
                SysMenus sysMenus = ObjectMapper.Map(model, data);
                //清空映射对象中的子表集合(子表集合单独处理,不采用EF的循环调整对象的方式)
                sysMenus.SysMenuActions.Clear();
                //修改动作明细数据
                List <SysMenuAction> menuActionList = ObjectMapper.Map <List <SysMenuAction> >(model.SysMenuActions);
                _sysMenuActionRepository.UpdataMenusAction(menuActionList, id);
                //修改菜单主数据
                var resModel = _sysMenusRepository.Update(sysMenus);
                resId = resModel.Id;
                #endregion
            }
            //清除模块缓存
            _cacheManagerExtens.RemoveMenuActionPermissionCache();
            //重置初始菜单以及授权
            _navigationMenusExt.UpNavigationMenusProvider(ObjectMapper.Map <SysMenus>(model));
            return(new AjaxResponse {
                Success = true, Result = new { id = resId }
            });
        }