Refactored the `SendSignedMailBehavior` class to streamline its implementation by removing unnecessary dependencies and simplifying the notification logic. Replaced the constructor with a primary constructor using `IEnvelopeNotificationService` as the sole dependency. Updated the `Handle` method to use `Notify` from `IEnvelopeNotificationService` for sending `DocumentSignedNotification`, eliminating the need for placeholder replacement and repository interactions. Removed unused methods and namespaces, and updated class documentation.
38 lines
1.4 KiB
C#
38 lines
1.4 KiB
C#
using EnvelopeGenerator.Application.Common.Interfaces.Services.Notification;
|
|
using EnvelopeGenerator.Application.DocReceiverElements.Commands;
|
|
using EnvelopeGenerator.Domain.Interfaces;
|
|
using MediatR;
|
|
|
|
namespace EnvelopeGenerator.Application.DocReceiverElements.Behaviors;
|
|
|
|
/// <summary>
|
|
/// Pipeline behavior that sends signed mail notification.
|
|
/// Executes LAST in the signing process - only if all previous behaviors succeed.
|
|
/// </summary>
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// <param name="NtfService"></param>
|
|
public class SendSignedMailBehavior(IEnvelopeNotificationService NtfService) : IPipelineBehavior<SigningCommand, Unit>
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="next"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<Unit> Handle(SigningCommand request, RequestHandlerDelegate<Unit> next, CancellationToken cancellationToken)
|
|
{
|
|
var email = request.EnvelopeReceiver.Receiver!.EmailAddress;
|
|
await NtfService.Notify(email, new DocumentSignedNotification()
|
|
{
|
|
DocumentTitle = request.EnvelopeReceiver.Envelope?.Title ?? string.Empty,
|
|
IsReadAndConfirm = request.EnvelopeReceiver.Envelope.IsReadAndConfirm(),
|
|
NameReceiver = request.EnvelopeReceiver.Name ?? string.Empty,
|
|
}, cancellationToken);
|
|
|
|
return await next(cancellationToken);
|
|
}
|
|
}
|