diff --git a/EnvelopeGenerator.API/Controllers/AnnotationController.cs b/EnvelopeGenerator.API/Controllers/AnnotationController.cs
index b99df64b..45dfd4b9 100644
--- a/EnvelopeGenerator.API/Controllers/AnnotationController.cs
+++ b/EnvelopeGenerator.API/Controllers/AnnotationController.cs
@@ -4,6 +4,7 @@ using EnvelopeGenerator.API.Extensions;
using EnvelopeGenerator.Application.Common.Extensions;
using EnvelopeGenerator.Application.Common.Interfaces.Services;
using EnvelopeGenerator.Application.Common.Notifications.DocSigned;
+using EnvelopeGenerator.Application.Common.Notifications.RemoveSignature;
using EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
using EnvelopeGenerator.Application.Histories.Queries;
using EnvelopeGenerator.Domain.Constants;
@@ -72,12 +73,24 @@ public class AnnotationController : ControllerBase
else if (await _mediator.AnyHistoryAsync(uuid, new[] { EnvelopeStatus.EnvelopeRejected, EnvelopeStatus.DocumentRejected }, cancel))
return Problem(statusCode: StatusCodes.Status423Locked);
- var docSignedNotification = await _mediator
- .ReadEnvelopeReceiverAsync(uuid, signature, cancel)
- .ToDocSignedNotification(psPdfKitAnnotation)
- ?? throw new NotFoundException("Envelope receiver is not found.");
+ var envelopeReceiverDto = await _mediator.ReadEnvelopeReceiverAsync(uuid, signature, cancel);
+ var docSignedNotification = envelopeReceiverDto is not null
+ ? new DocSignedNotification(envelopeReceiverDto) { PsPdfKitAnnotation = psPdfKitAnnotation }
+ : throw new NotFoundException("Envelope receiver is not found.");
- await _mediator.PublishSafely(docSignedNotification, cancel);
+ try
+ {
+ await _mediator.Publish(docSignedNotification, cancel);
+ }
+ catch (Exception)
+ {
+ await _mediator.Publish(new RemoveSignatureNotification()
+ {
+ EnvelopeId = docSignedNotification.EnvelopeId,
+ ReceiverId = docSignedNotification.ReceiverId
+ }, cancel);
+ throw;
+ }
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return Ok();
diff --git a/EnvelopeGenerator.Application/Common/Notifications/DocSigned/DocSignedNotification.cs b/EnvelopeGenerator.Application/Common/Notifications/DocSigned/DocSignedNotification.cs
index 6312ad9c..802519dd 100644
--- a/EnvelopeGenerator.Application/Common/Notifications/DocSigned/DocSignedNotification.cs
+++ b/EnvelopeGenerator.Application/Common/Notifications/DocSigned/DocSignedNotification.cs
@@ -37,52 +37,4 @@ public record DocSignedNotification(EnvelopeReceiverDto Original) : EnvelopeRece
public string EmailAddress => Receiver?.EmailAddress
?? throw new InvalidOperationException($"Receiver is null." +
$"DocSignedNotification:\n{this.ToJson(Format.Json.ForDiagnostics)}");
-}
-
-///
-///
-///
-public static class DocSignedNotificationExtensions
-{
- ///
- /// Converts an to a .
- ///
- /// The DTO to convert.
- ///
- /// A new instance.
- public static DocSignedNotification ToDocSignedNotification(this EnvelopeReceiverDto dto, PsPdfKitAnnotation psPdfKitAnnotation)
- => new(dto) { PsPdfKitAnnotation = psPdfKitAnnotation };
-
- ///
- ///
- ///
- ///
- ///
- ///
- public static async Task ToDocSignedNotification(this Task dtoTask, PsPdfKitAnnotation? psPdfKitAnnotation)
- => await dtoTask is EnvelopeReceiverDto dto ? new(dto) { PsPdfKitAnnotation = psPdfKitAnnotation } : null;
-
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static async Task PublishSafely(this IPublisher publisher, DocSignedNotification notification, CancellationToken cancel = default)
- {
- try
- {
- await publisher.Publish(notification, cancel);
- }
- catch (Exception)
- {
- await publisher.Publish(new RemoveSignatureNotification()
- {
- EnvelopeId = notification.EnvelopeId,
- ReceiverId = notification.ReceiverId
- }, cancel);
- throw;
- }
- }
}
\ No newline at end of file
diff --git a/EnvelopeGenerator.Tests/Application/DocSignedNotificationTests.cs b/EnvelopeGenerator.Tests/Application/DocSignedNotificationTests.cs
index 1f44e1dd..9d2bd900 100644
--- a/EnvelopeGenerator.Tests/Application/DocSignedNotificationTests.cs
+++ b/EnvelopeGenerator.Tests/Application/DocSignedNotificationTests.cs
@@ -53,7 +53,7 @@ public class DocSignedNotificationTests : TestBase
var annots = Services.GetRequiredService();
- var docSignedNtf = envRcvDto.ToDocSignedNotification(annots);
+ var docSignedNtf = new DocSignedNotification(envRcvDto) { PsPdfKitAnnotation = annots };
var sendSignedMailHandler = Host.Services.GetRequiredService();
diff --git a/EnvelopeGenerator.Web/Controllers/AnnotationController.cs b/EnvelopeGenerator.Web/Controllers/AnnotationController.cs
index 0cecccf0..adc4a041 100644
--- a/EnvelopeGenerator.Web/Controllers/AnnotationController.cs
+++ b/EnvelopeGenerator.Web/Controllers/AnnotationController.cs
@@ -3,6 +3,7 @@ using DigitalData.Core.Exceptions;
using EnvelopeGenerator.Application.Common.Extensions;
using EnvelopeGenerator.Application.Common.Interfaces.Services;
using EnvelopeGenerator.Application.Common.Notifications.DocSigned;
+using EnvelopeGenerator.Application.Common.Notifications.RemoveSignature;
using EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
using EnvelopeGenerator.Application.Histories.Queries;
using EnvelopeGenerator.Domain.Constants;
@@ -69,12 +70,24 @@ public class AnnotationController : ControllerBase
else if (er.Envelope.IsReadAndSign() && await _mediator.AnyHistoryAsync(uuid, new[] { EnvelopeStatus.EnvelopeRejected, EnvelopeStatus.DocumentRejected }, cancel))
return Problem(statusCode: 423);
- var docSignedNotification = await _mediator
- .ReadEnvelopeReceiverAsync(uuid, signature, cancel)
- .ToDocSignedNotification(psPdfKitAnnotation)
- ?? throw new NotFoundException("Envelope receiver is not found.");
+ var envelopeReceiverDto = await _mediator.ReadEnvelopeReceiverAsync(uuid, signature, cancel);
+ var docSignedNotification = envelopeReceiverDto is not null
+ ? new DocSignedNotification(envelopeReceiverDto) { PsPdfKitAnnotation = psPdfKitAnnotation }
+ : throw new NotFoundException("Envelope receiver is not found.");
- await _mediator.PublishSafely(docSignedNotification, cancel);
+ try
+ {
+ await _mediator.Publish(docSignedNotification, cancel);
+ }
+ catch (Exception)
+ {
+ await _mediator.Publish(new RemoveSignatureNotification()
+ {
+ EnvelopeId = docSignedNotification.EnvelopeId,
+ ReceiverId = docSignedNotification.ReceiverId
+ }, cancel);
+ throw;
+ }
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);