public async Task Execute(IJobExecutionContext context) { foreach (BotSubscriptionServiceModel botSubscription in _botSubscriptionService.GetAll()) { var todayTopics = _botSubscriptionService.GetActualTopics(botSubscription.PlanId).ToList(); if (todayTopics.Any()) { foreach (var topic in todayTopics) { await _botService.Client.SendTextMessageAsync(botSubscription.ChatId, $"Your today's topic is {topic.Name}\r\nDue date: {topic.EndDate}.\r\nSource: {topic.Source}\r\nGood luck!"); } } } }
private static void Process() { IServiceScope scope = _serviceProvider.CreateScope(); IBotSubscriptionService botSubscriptionService = (IBotSubscriptionService)scope.ServiceProvider.GetService(typeof(IBotSubscriptionService)); foreach (BotSubscriptionServiceModel botSubscription in botSubscriptionService.GetAll()) { var todayTopics = botSubscriptionService.GetActualTopics(botSubscription.PlanId).ToList(); if (todayTopics.Any()) { foreach (var topic in todayTopics) { _client.SendTextMessageAsync(botSubscription.ChatId, $"Your today's topic is {topic.Name}\r\nDue date: {topic.EndDate}.\r\nSource: {topic.Source}\r\nGood luck!").GetAwaiter().GetResult(); } } else { //TODO add plan.IsFinished } } }