public virtual List <MenuItemDto> GetUserMenuItems(string userId) { using (var db = GetDbContext()) { var tsUser = db.GetTable <TsUser>() .FirstOrDefault(x => x.Id.Equals(userId)); var result = new List <MenuItemDto>(); if (tsUser.CUserType == 9) { result = db.GetTable <TsResource>() .Where(x => x.CType.Equals(2)) .Select(x => MenuItemDto.Map(x)) .ToList(); } else { var roles = GetUserRoles(userId); var resourceIds = db.GetTable <TsRolePermission>() .Where(x => roles.Contains(x.CRoleId) && (x.CResourceType.Equals(2) || x.CResourceType.Equals(64))) .Select(x => x.CResourceId) .ToList(); result = db.GetTable <TsResource>() .Where(x => resourceIds.Contains(x.Id)) .OrderBy(x => x.COrder) .Select(x => MenuItemDto.Map(x)) .ToList(); } return(result); } }
/// <summary> /// 根据ID获取模块信息 /// </summary> /// <param name="id">主键</param> /// <returns></returns> public virtual MenuItemDto GetById(string id) { using (var db = GetDbContext()) { return(db.GetTable <TsResource>() .Select(x => MenuItemDto.Map(x)) .FirstOrDefault(x => x.Id == id)); } }