Ejemplo n.º 1
0
        /// <summary>
        /// 修改角色和菜单的关联关系
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="lstMenuId"></param>
        /// <returns></returns>
        public async Task <ResultEntity> EditRoleMenu(int roleId, IList <int> lstMenuId)
        {
            var resultEntity = new ResultEntity();

            //生成本次批次号
            var roleMenu = _roleMenuRepository.GetQueryable().FirstOrDefault(a => a.RoleId == roleId);
            var batchNo  = roleMenu?.BatchNo + 1 ?? 1;

            //删除现有数据
            DeleteRoleMenus(roleId);
            //添加新增数据
            foreach (var menuId in lstMenuId)
            {
                var newRoleMenu = new RoleMenu
                {
                    RoleId  = roleId,
                    MenuId  = menuId,
                    BatchNo = batchNo
                };
                await _roleMenuRepository.AddAsync(newRoleMenu);
            }


            resultEntity.Success = true;
            return(resultEntity);
        }