1- using System ;
2- using System . Diagnostics ;
31using System . IO ;
42using System . Linq ;
5- using System . Text ;
6- using System . Security . Cryptography ;
73using System . Collections . Generic ;
84using Microsoft . AspNetCore . Hosting ;
95using QueryTree . Models ;
10- using Microsoft . Extensions . PlatformAbstractions ;
116using Newtonsoft . Json ;
127using MimeKit ;
138using Microsoft . EntityFrameworkCore ;
149using Microsoft . Extensions . Configuration ;
1510using Microsoft . Extensions . Caching . Memory ;
11+ using QueryTree . Services ;
1612
1713namespace QueryTree . Managers
1814{
@@ -24,22 +20,25 @@ public interface IScheduledEmailManager
2420
2521 public class ScheduledEmailManager : IScheduledEmailManager
2622 {
27- private IEmailSender _emailSender ;
28- private IConfiguration _config ;
29- private ApplicationDbContext _db ;
30- private DbManager _dbMgr ;
31- private IHostingEnvironment _env ;
32- private ConvertManager _convertManager ;
33-
34-
35- public ScheduledEmailManager (
36- IEmailSender emailSender ,
37- IConfiguration config ,
23+ private readonly IEmailSenderService _emailSenderService ;
24+ private readonly IEmailSender _emailSender ;
25+ private readonly IConfiguration _config ;
26+ private readonly ApplicationDbContext _db ;
27+ private readonly DbManager _dbMgr ;
28+ private readonly IHostingEnvironment _env ;
29+ private readonly ConvertManager _convertManager ;
30+
31+
32+ public ScheduledEmailManager (
33+ IEmailSenderService emailSenderService ,
34+ IEmailSender emailSender ,
35+ IConfiguration config ,
3836 ApplicationDbContext db ,
3937 IHostingEnvironment env ,
4038 IMemoryCache cache ,
4139 IPasswordManager passwordManager )
4240 {
41+ _emailSenderService = emailSenderService ;
4342 _emailSender = emailSender ;
4443 _config = config ;
4544 _db = db ;
@@ -54,8 +53,13 @@ public void BuildScheduledEmail(string queryName, string editUrl, string recipie
5453 {
5554 return ;
5655 }
57-
58- var query = _db . Queries
56+
57+ if ( ! _emailSenderService . TrySetDelivered ( queryId ) )
58+ {
59+ return ;
60+ }
61+
62+ var query = _db . Queries
5963 . Include ( q => q . DatabaseConnection )
6064 . FirstOrDefault ( q => q . QueryID == queryId ) ;
6165
0 commit comments