refactor(envelope): consolidate draft flow into upsert command
- extend CreateEnvelopeCommand to support draft updates and send intent - merge draft save logic into CreateEnvelopeCommandHandler and remove duplicate handler - add DocReceiverElement writer abstraction and infrastructure registration for SQL-based field upserts
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
#if NET
|
||||
using EnvelopeGenerator.Application.Common.Interfaces;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure.Writers;
|
||||
|
||||
public class DocReceiverElementWriter(EGDbContext dbContext) : IDocReceiverElementWriter
|
||||
{
|
||||
public Task DeleteByDocumentAndReceiverAsync(int documentId, int receiverId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return dbContext.Database.ExecuteSqlInterpolatedAsync(
|
||||
$"DELETE FROM [dbo].[TBSIG_DOCUMENT_RECEIVER_ELEMENT] WHERE [DOCUMENT_ID] = {documentId} AND [RECEIVER_ID] = {receiverId}",
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
public Task InsertAsync(DocReceiverElement element, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return dbContext.Database.ExecuteSqlInterpolatedAsync($@"
|
||||
INSERT INTO [dbo].[TBSIG_DOCUMENT_RECEIVER_ELEMENT]
|
||||
([DOCUMENT_ID]
|
||||
,[RECEIVER_ID]
|
||||
,[ELEMENT_TYPE]
|
||||
,[POSITION_X]
|
||||
,[POSITION_Y]
|
||||
,[WIDTH]
|
||||
,[HEIGHT]
|
||||
,[REQUIRED]
|
||||
,[READ_ONLY]
|
||||
,[PAGE]
|
||||
,[ADDED_WHEN]
|
||||
,[FULL_NAME]
|
||||
,[POSITION]
|
||||
,[PLACE]
|
||||
,[TOOLTIP]
|
||||
,[ANNOTATION_INDEX])
|
||||
VALUES ({element.DocumentId}
|
||||
,{element.ReceiverId}
|
||||
,{element.ElementType}
|
||||
,{element.X}
|
||||
,{element.Y}
|
||||
,{element.Width}
|
||||
,{element.Height}
|
||||
,{element.Required}
|
||||
,{element.ReadOnly}
|
||||
,{element.Page}
|
||||
,{element.AddedWhen}
|
||||
,{element.FullName}
|
||||
,{element.Position}
|
||||
,{element.Place}
|
||||
,{element.Tooltip}
|
||||
,{element.AnnotationIndex})",
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user