예제 #1
0
        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 });
                }
            }
        }