public async Task OnGet() { var usersInMemberRole = await _userManager.GetUsersInRoleAsync(AuthConstants.Roles.MEMBERS); var usersInAlumniRole = await _userManager.GetUsersInRoleAsync(AuthConstants.Roles.ALUMNI); var memberUserIds = usersInMemberRole.Select(x => x.Id).ToList(); var alumniUserIds = usersInAlumniRole.Select(x => x.Id).ToList(); var memberSpec = new MembersHavingUserIdsWithBooksSpec(memberUserIds); var members = await _repository.ListAsync(memberSpec); var alumniSpec = new MembersHavingUserIdsWithBooksSpec(alumniUserIds); var alumni = await _repository.ListAsync(alumniSpec); Members = members .Where(m => (m.BooksRead?.Count ?? 0) > 0 && !alumni.Any(alumni => alumni.Id == m.Id)) .Select(member => MemberLinksDTO.FromMemberEntity(member)) .ToList(); Alumni = alumni.Select(alumni => MemberLinksDTO.FromMemberEntity(alumni)) .Where(m => (m.BooksRead?.Count ?? 0) > 0) .ToList(); var bookSpec = new BooksByMemberReadCountWithMembersWhoHaveReadSpec(); Books = await _repository.ListAsync(bookSpec); }
public async Task OnGet() { var usersInMemberRole = await _userManager.GetUsersInRoleAsync(AuthConstants.Roles.MEMBERS); var usersInAlumniRole = await _userManager.GetUsersInRoleAsync(AuthConstants.Roles.ALUMNI); var memberUserIds = usersInMemberRole.Select(x => x.Id).ToList(); var alumniUserIds = usersInAlumniRole.Select(x => x.Id).ToList(); var memberSpec = new MembersHavingUserIdsWithBooksSpec(memberUserIds); var members = await _memberRepository.ListAsync(memberSpec); var alumniSpec = new MembersHavingUserIdsWithBooksSpec(alumniUserIds); var alumni = await _memberRepository.ListAsync(alumniSpec); Members = members .Where(m => (m.BooksRead?.Count ?? 0) > 0 && !alumni.Any(alumni => alumni.Id == m.Id)) .Select(member => MemberLinksDTO.FromMemberEntity(member)) .ToList(); var memberRanks = _rankingService.Rank(Members.Select(m => m.BooksRead !.Count)); Members.ForEach(m => m.Rank = memberRanks[m.BooksRead !.Count]);