public MenusInput GetMenusModel(long id) { //查询模块以及所包含的授权动作 var data = _sysMenusRepository.Get(id); //或使用如下方式效果同上 //var data = _sysMenusRepository.GetAllIncluding(x => x.SysMenuActions).FirstOrDefault(x => x.Id == id); return(data.MapTo <MenusInput>()); }
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 } }); }