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`.
54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
using DigitalData.TaskFlow.Application.Common.Interfaces;
|
|
using DigitalData.TaskFlow.Domain.ProcedureResults;
|
|
using DigitalData.TaskFlow.Infrastructure.Persistence;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace DigitalData.TaskFlow.Infrastructure.Repositories;
|
|
|
|
/// <summary>
|
|
/// Workflow repository implementation for reading workflow listing data and applying close operations.
|
|
/// </summary>
|
|
public sealed class WorkflowRepository(TaskFlowDbContext context) : IWorkflowRepository
|
|
{
|
|
public async Task<Workflow?> 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<WorkflowClosing?> 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();
|
|
}
|
|
}
|