public async Task <IActionResult> GetMySettings() { var currentUser = await _userService.GetCurrent(); var settings = await _mailingSettingService.Get(currentUser); return(Ok(new MailingSettingsDto { ScheduleType = _cronService.ExpressionToSchedule(settings.Schedule), NumberOfArticles = settings.NumberOfArticles })); }
private async Task SendEmail(IServiceScope serviceScope, MailingSettings settings) { var articleService = serviceScope.ServiceProvider.GetRequiredService <ArticleService>(); var articles = await articleService.GetForSending(settings.User, settings.NumberOfArticles); if (articles.Count == 0) { _logger.LogInformation("No articles to send for {email}", settings.User.Email); return; } var usersService = serviceScope.ServiceProvider.GetRequiredService <UsersService>(); var unsubscribeToken = usersService.GetUnsubscribeTokenByUser(settings.User); await _mailService.SendArticleList(settings.User, unsubscribeToken, articles, _cronService.ExpressionToSchedule(settings.Schedule)); await articleService.MarkAsSent(articles, settings.User); }