| | | 1 | | using MechanicsSoftware.Application.Abstractions; |
| | | 2 | | using MechanicsSoftware.Application.Exceptions; |
| | | 3 | | using MechanicsSoftware.Domain.Entities; |
| | | 4 | | using Microsoft.Extensions.Logging; |
| | | 5 | | |
| | | 6 | | namespace MechanicsSoftware.Application.UseCases.ServiceOrders.Handlers; |
| | | 7 | | |
| | | 8 | | internal static class EmailExtensions |
| | | 9 | | { |
| | | 10 | | internal static async Task TrySendStatusEmailAsync( |
| | | 11 | | this IEmailNotifier emailNotifier, |
| | | 12 | | IAppDbContext db, |
| | | 13 | | ILogger logger, |
| | | 14 | | ServiceOrder order, |
| | | 15 | | CancellationToken cancellationToken) |
| | 40 | 16 | | { |
| | | 17 | | try |
| | 40 | 18 | | { |
| | 40 | 19 | | var customer = await db.Customers.FindAsync([order.CustomerId], cancellationToken) |
| | 40 | 20 | | ?? throw new NotFoundException(nameof(Customer), order.CustomerId); |
| | | 21 | | |
| | 16 | 22 | | await emailNotifier.SendStatusChangedAsync( |
| | 16 | 23 | | toEmail: customer.Email.Value, |
| | 16 | 24 | | customerName: customer.Name, |
| | 16 | 25 | | serviceOrderId: order.Id, |
| | 16 | 26 | | newStatus: order.Status.Value, |
| | 16 | 27 | | cancellationToken: cancellationToken); |
| | 8 | 28 | | } |
| | 32 | 29 | | catch (Exception ex) |
| | 32 | 30 | | { |
| | 32 | 31 | | logger.FailedToSendStatusEmail(ex, order.Id); |
| | 32 | 32 | | } |
| | 40 | 33 | | } |
| | | 34 | | } |