From 210c1f414c8e3fd190f64828c70ae1ffd2e55cb5 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 3 Nov 2026 20:44:08 +0100 Subject: [PATCH] Add CloseAsync method to WorkflowRepository Introduced a new asynchronous method `CloseAsync` in the `WorkflowRepository` class to handle workflow process closing. This method executes the `PRCUST_F19_CLOSING` stored procedure with parameters for user ID, source, process ID, closing method ID, comment, and rejection reason ID. It uses `FromSqlInterpolated` for safe SQL parameterization and retrieves results with `AsNoTracking()` and `ToListAsync(cancellationToken)`. The method returns the first result as a `WorkflowClosing` object or `null`. --- .../Repositories/WorkflowRepository.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/infrastructure/DigitalData.TaskFlow.Infrastructure/Repositories/WorkflowRepository.cs b/src/infrastructure/DigitalData.TaskFlow.Infrastructure/Repositories/WorkflowRepository.cs index 2487116..452687f 100644 --- a/src/infrastructure/DigitalData.TaskFlow.Infrastructure/Repositories/WorkflowRepository.cs +++ b/src/infrastructure/DigitalData.TaskFlow.Infrastructure/Repositories/WorkflowRepository.cs @@ -19,4 +19,35 @@ public sealed class WorkflowRepository(TaskFlowDbContext context) : IWorkflowRep return rows.FirstOrDefault(); } + + public async Task CloseAsync( + int userId, + string source, + long processId, + int closingMethodId, + string? comment, + byte? rejectionReasonId, + CancellationToken cancellationToken) + { + var rows = await context.WorkflowClosings + .FromSqlInterpolated($@" +DECLARE @ResultCode INT; +DECLARE @ResultMessage NVARCHAR(400); + +EXEC dbo.PRCUST_F19_CLOSING + @UserID = {userId}, + @Source = {source}, + @ProcessID = {processId}, + @ClosingMethodID = {closingMethodId}, + @Comment = {comment}, + @RejectionReasonID = {rejectionReasonId}, + @ResultCode = @ResultCode OUTPUT, + @ResultMessage = @ResultMessage OUTPUT; + +SELECT @ResultCode AS CODE, @ResultMessage AS RESULT;") + .AsNoTracking() + .ToListAsync(cancellationToken); + + return rows.FirstOrDefault(); + } }