private async Task GetTopNAndRespond(Update update, int N) { var msgDate = update.Message.Date.Date; var chatId = update.Message.Chat.Id; var dateSpan = TimeSpan.FromDays(6); var counters = await _counterDatedDao.GetCounters(chatId, msgDate - dateSpan, msgDate, N); var countersSummed = counters.GroupBy(c => (c.ChatId, c.UserId)) .Select(g => (g.Key, g.Sum(c => c.Value))); var userCounters = await Task.WhenAll(countersSummed.Select(async(c) => new { User = await _userDao.GetUserById(c.Key.UserId), Counter = c.Item2 })); var result = userCounters .Select(uc => ( (uc.User != null ? uc.User.FirstName + " " + uc.User.LastName : "%Unknown%").Escape(), uc.Counter)); var text = CreateText(result); await _client.SendTextMessageAsync( update.Message.Chat.Id, text, replyToMessageId : update.Message.MessageId, parseMode : ParseMode.Html); }
private async Task GetTopNAndRespond(Update update, int N) { var date = update.Message.Date.Date; var counters = await _counterDatedDao.GetCounters(update.Message.Chat.Id, date, N); var userCounters = await Task.WhenAll(counters.Select(async(c) => new { User = await _userDao.GetUserById(c.UserId), Counter = c.Value })); var result = userCounters .Select(uc => ( (uc.User != null ? uc.User.FirstName + " " + uc.User.LastName : "%Unknown%").Escape(), uc.Counter)); var text = CreateText(result, date); await _client.SendTextMessageAsync( update.Message.Chat.Id, text, replyToMessageId : update.Message.MessageId, parseMode : ParseMode.Html); }