public async Task AddBulkExperience(List <User> users, long experience, string channel) { var levels = users.ToDictionary(user => user.Id, user => user.Level); var userIds = users.Select(user => user.Id).ToList(); _statsRepository.AddExperienceToUsers(userIds, experience); var tasks = users.Select(user => BroadcastExperienceGain(user, levels.GetValueOrDefault(user.Id), experience, channel)); await Task.WhenAll(tasks); }
public async Task AddBulkExperience(List <User> users, long experience, string channel) { var levels = users.ToDictionary(user => user.Id, user => user.Level); var userIds = users.Select(user => user.Id).ToList(); _statsRepository.AddExperienceToUsers(userIds, experience); var expGainMessageTasks = users.Select(user => _slack.SendEphemeralMessage(string.Format(DougMessages.GainedExp, experience), user.Id, channel)); var levelUpUsers = users.Where(user => levels.GetValueOrDefault(user.Id) < user.Level).ToList(); LevelUpUsers(levelUpUsers); var levelUpMessageTasks = levelUpUsers.Select(user => _slack.BroadcastMessage(string.Format(DougMessages.LevelUp, Mention(user), user.Level), channel)); await Task.WhenAll(expGainMessageTasks); await Task.WhenAll(levelUpMessageTasks); }