Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Test([FromRoute] string email)
        {
            var user = await _userService.GetUserByEmail(email);

            if (user == null)
            {
                return(NotFound("User not found"));
            }

            var articles = await _articleService.GetForReading(user);

            await _mailService.SendArticleList(user, string.Empty, articles, ScheduleType.EveryMonth);

            return(Ok(new UserDto
            {
                Id = user.Id,
                Email = user.Email,
                Name = user.Name,
                PictureUrl = user.PictureUrl,
                Language = user.Language,
                IsAdmin = user.IsAdmin
            }));
        }