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