public async Task <IEnumerable <ChannelDetails> > GetChannels(IEnumerable <int> channelIds, User activeUser) { var allUserChannelIds = await MessageRepo.GetChannelsForUser(activeUser.Id); if (channelIds == null || !channelIds.Any()) { channelIds = allUserChannelIds; } else { channelIds = channelIds.Intersect(allUserChannelIds); } var channels = await MessageRepo.GetChannels(channelIds.ToArray()); Dictionary <int, IEnumerable <int> > channelIdToUserIds = new Dictionary <int, IEnumerable <int> >(); foreach (var channel in channels) { channelIdToUserIds.Add(channel.Id, await MessageRepo.GetAllChannelMemberIds(channel.Id)); } var users = await UserDomain.RetrieveUsers(channelIdToUserIds.SelectMany(val => val.Value)); var channelsDetails = channels.Select(c => { var channelUsers = users.Where(u => channelIdToUserIds[c.Id].Contains(u.Id)); return(new ChannelDetails() { Channel = c, Users = channelUsers, Usernames = channelUsers.Select(u => u.Username) }); }); return(channelsDetails); }
public async Task <IEnumerable <ShopDetails> > GetShopDetails(int[] shopIds) { var shops = (await ShopRepo.RetrieveShopsById(shopIds)); var users = (await UserDomain.RetrieveUsers(shops.Where(s => s.OwnerUserId != null).Select(s => s.OwnerUserId.Value))); return(shops.Select(s => { return new ShopDetails() { Shop = s, Owner = s.OwnerUserId.HasValue ? users.Where(u => u.Id == s.OwnerUserId).FirstOrDefault() : null }; })); }
public async Task <IEnumerable <LeaderboardEntryDetails> > RetrieveLeaderboard(GameType gameId) { var now = DateTime.UtcNow; var month = new DateTime(now.Year, now.Month, 1); GameConfig gameCfg = (await ConfigRepo.RetrieveGamesConfigByIds(true, gameId)).FirstOrDefault(); int topCount = gameCfg.LeaderboardMaxSpot ?? 10; IEnumerable <LeaderboardEntry> leaderboard = await GameRepo.GetLeaderboard(gameId, topCount, month); List <int> users = leaderboard.Select(le => le.PlayerUserId).AsList(); Dictionary <int, string> userNames = (await UserDomain.RetrieveUsers(users)).ToDictionary(user => user.Id, user => user.Username); IEnumerable <LeaderboardEntryDetails> retVal = leaderboard.Select(le => new LeaderboardEntryDetails { Entry = le, Username = userNames.GetValueOrDefault(le.PlayerUserId, "Unknown") }); return(retVal); }