1
- using Microsoft . AspNetCore . Authorization ;
2
- using Microsoft . AspNetCore . Identity ;
1
+ using Microsoft . AspNetCore . Identity ;
2
+ using Microsoft . AspNetCore . Identity . UI . Services ;
3
3
using Microsoft . AspNetCore . Mvc ;
4
4
using Microsoft . EntityFrameworkCore ;
5
5
using System . Text . Json ;
10
10
using Waffle . ExternalAPI . Models ;
11
11
using Waffle . Models . Components ;
12
12
using Waffle . Models . Settings ;
13
+ using Waffle . UnitTest ;
14
+ using WFSendGrid = Waffle . ExternalAPI . SendGrids . SendGrid ;
13
15
14
16
namespace Waffle . Controllers ;
15
17
@@ -21,15 +23,17 @@ public class AppSettingController : BaseController
21
23
private readonly IFacebookService _facebookService ;
22
24
private readonly ITelegramService _telegramService ;
23
25
private readonly IWorkService _workService ;
26
+ private readonly IEmailSender _emailSender ;
24
27
25
- public AppSettingController ( ApplicationDbContext context , IAppSettingService appSettingService , IConfiguration configuration , IFacebookService facebookService , ITelegramService telegramService , IWorkService workService )
28
+ public AppSettingController ( IEmailSender emailSender , ApplicationDbContext context , IAppSettingService appSettingService , IConfiguration configuration , IFacebookService facebookService , ITelegramService telegramService , IWorkService workService )
26
29
{
27
30
_context = context ;
28
31
_appSettingService = appSettingService ;
29
32
_configuration = configuration ;
30
33
_facebookService = facebookService ;
31
34
_telegramService = telegramService ;
32
35
_workService = workService ;
36
+ _emailSender = emailSender ;
33
37
}
34
38
35
39
[ HttpGet ( "by-name/{normalizedName}" ) ]
@@ -58,18 +62,14 @@ public IActionResult GetInfo()
58
62
public async Task < IActionResult > GetSendGridAsync ( )
59
63
{
60
64
var app = await _appSettingService . EnsureSettingAsync ( nameof ( SendGrid ) ) ;
61
- return base . Ok ( await _appSettingService . GetAsync < ExternalAPI . SendGrids . SendGrid > ( app . Id ) ) ;
65
+ return base . Ok ( await _appSettingService . GetAsync < WFSendGrid > ( app . Id ) ) ;
62
66
}
63
67
64
68
[ HttpPost ( "sendgrid/save" ) ]
65
- public async Task < IActionResult > SaveSendGridAsync ( [ FromBody ] ExternalAPI . SendGrids . SendGrid args )
69
+ public async Task < IActionResult > SaveSendGridAsync ( [ FromBody ] WFSendGrid args )
66
70
{
67
- var setting = await _context . AppSettings . FirstOrDefaultAsync ( x => x . NormalizedName . Equals ( nameof ( SendGrid ) ) ) ;
68
- if ( setting == null )
69
- {
70
- return Ok ( IdentityResult . Failed ( ) ) ;
71
- }
72
- setting . Value = JsonSerializer . Serialize ( args ) ;
71
+ var app = await _appSettingService . EnsureSettingAsync ( nameof ( SendGrid ) ) ;
72
+ app . Value = JsonSerializer . Serialize ( args ) ;
73
73
await _context . SaveChangesAsync ( ) ;
74
74
return Ok ( IdentityResult . Success ) ;
75
75
}
@@ -202,4 +202,11 @@ public async Task<IActionResult> GetSidebarAsync()
202
202
203
203
[ HttpPost ( "delete/work/{id}" ) ]
204
204
public async Task < IActionResult > DeleteWorkAsync ( [ FromRoute ] Guid id ) => Ok ( await _appSettingService . DeleteWorkAsync ( id ) ) ;
205
+
206
+ [ HttpPost ( "test-send-mail" ) ]
207
+ public async Task < IActionResult > TestSendMailAsync ( [ FromBody ] EmailSenderMessageUnitTest args )
208
+ {
209
+ await _emailSender . SendEmailAsync ( args . Email , args . Subject , args . Message ) ;
210
+ return Ok ( args ) ;
211
+ }
205
212
}
0 commit comments