public async Task Execute(IJobExecutionContext context) { DateTime[] actualMenuDates = await _botRepository.GetActualMenuDates(); Dictionary <string, DateTime[]> noOrdersForDatesByUser = await _foodRepository.NoOrderDatesByUserEmail(actualMenuDates); if (noOrdersForDatesByUser.Count > 0) { ILookup <string, (Messenger Messenger, string ExternalId)> externalIds = await _botRepository.GetExternalIdByUserEmail(noOrdersForDatesByUser.Keys); foreach (IGrouping <string, (Messenger Messenger, string ExternalId)> externalIdGroup in externalIds) { string dates = string.Join(", ", noOrdersForDatesByUser[externalIdGroup.Key].Select(d => d.ToShortDateString())); string message = $"Еда не заказана на {dates}. Это можно исправить тут {_appConfig.FoodMenuLink}"; Destination[] destinations = externalIdGroup.Select(g => new Destination { Messenger = g.Messenger, UserId = g.ExternalId, ChannelId = g.ExternalId }).ToArray(); await _messageSender.SendAsync(destinations, new BotResponse { Text = message }); } } }
public async Task Execute(IJobExecutionContext context) { DateTime[] actualMenuDates = await _botRepository.GetActualMenuDates(); DateTime[] newMenuDates = await _foodRepository.NewMenuDates(actualMenuDates.Max()); if (newMenuDates.Length > 0) { await _botRepository.SaveActualMenuDates(newMenuDates); string message = $"Меню на {newMenuDates.Min().ToShortDateString()} - {newMenuDates.Max().ToShortDateString()} выложено"; await _messageSender.SendAsync( new[] { new Destination { Messenger = Messenger.Slack, ChannelId = _appConfig.SlackOfficeChat }, new Destination { Messenger = Messenger.Skype, ChannelId = _appConfig.SkypeOfficeChat } }, new BotResponse { Text = message }); } }