using DigitalData.TaskFlow.Application.Common.Interfaces; using DigitalData.TaskFlow.Domain.ProcedureResults; using DigitalData.TaskFlow.Infrastructure.Persistence; using Microsoft.EntityFrameworkCore; namespace DigitalData.TaskFlow.Infrastructure.Repositories; /// /// Workflow repository implementation for reading workflow listing data and applying close operations. /// public sealed class WorkflowRepository(TaskFlowDbContext context) : IWorkflowRepository { public async Task GetByWisagIdAsync(int wisagId, CancellationToken cancellationToken) { var rows = await context.Workflows .FromSqlInterpolated(@$"EXEC [PRCUST_F19_GET_LISTING_DATA] @pUSER_ID = {wisagId}, @pRESULT_TYPE = 'json', @pOBJECT_TYPE = 'Ferdinand'") .AsNoTracking() .ToListAsync(cancellationToken); 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(); } }