Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #26

Merged
merged 6 commits into from
Feb 15, 2025
Merged

Dev #26

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Blocktrust.CredentialWorkflow.Core.Commands.WorkflowOutcome.GetWorkflowOutcomeById;

using Blocktrust.CredentialWorkflow.Core.Domain.ProcessFlow.Actions;
using Domain.Workflow;
using FluentResults;
using MediatR;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
namespace Blocktrust.CredentialWorkflow.Core.Commands.WorkflowOutcome.GetWorkflowOutcomeIdsByState
namespace Blocktrust.CredentialWorkflow.Core.Commands.WorkflowOutcome.GetWorkflowOutcomeIdsByState;

using FluentResults;
using MediatR;
using Microsoft.EntityFrameworkCore;

public class GetWorkflowOutcomeIdsByStateHandler
: IRequestHandler<GetWorkflowOutcomeIdsByStateRequest, Result<List<GetWorkflowOutcomeIdsByStateResponse>>>
{
using FluentResults;
using MediatR;
using Microsoft.EntityFrameworkCore;
private readonly DataContext _context;

public class GetWorkflowOutcomeIdsByStateHandler
: IRequestHandler<GetWorkflowOutcomeIdsByStateRequest, Result<List<GetWorkflowOutcomeIdsByStateResponse>>>
public GetWorkflowOutcomeIdsByStateHandler(DataContext context)
{
private readonly DataContext _context;

public GetWorkflowOutcomeIdsByStateHandler(DataContext context)
{
_context = context;
}
_context = context;
}

public async Task<Result<List<GetWorkflowOutcomeIdsByStateResponse>>> Handle(
GetWorkflowOutcomeIdsByStateRequest request,
CancellationToken cancellationToken)
{
var outcomes = await _context.WorkflowOutcomeEntities
.Where(o => request.WorkflowOutcomeStates.Contains(o.WorkflowOutcomeState))
.Select(o => new GetWorkflowOutcomeIdsByStateResponse
{
OutcomeId = o.WorkflowOutcomeEntityId,
WorkflowOutcomeState = o.WorkflowOutcomeState
})
.ToListAsync(cancellationToken);
public async Task<Result<List<GetWorkflowOutcomeIdsByStateResponse>>> Handle(
GetWorkflowOutcomeIdsByStateRequest request,
CancellationToken cancellationToken)
{
var outcomes = await _context.WorkflowOutcomeEntities
.Where(o => request.WorkflowOutcomeStates.Contains(o.WorkflowOutcomeState))
.Select(o => new GetWorkflowOutcomeIdsByStateResponse
{
OutcomeId = o.WorkflowOutcomeEntityId,
WorkflowOutcomeState = o.WorkflowOutcomeState
})
.ToListAsync(cancellationToken);

return Result.Ok(outcomes);
}
return Result.Ok(outcomes);
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
namespace Blocktrust.CredentialWorkflow.Core.Commands.WorkflowOutcome.UpdateWorkflowOutcomeState
namespace Blocktrust.CredentialWorkflow.Core.Commands.WorkflowOutcome.UpdateWorkflowOutcomeState;

using FluentResults;
using MediatR;
using Microsoft.EntityFrameworkCore;

public class UpdateWorkflowOutcomeStateHandler : IRequestHandler<UpdateWorkflowOutcomeStateRequest, Result>
{
using FluentResults;
using MediatR;
using Microsoft.EntityFrameworkCore;
private readonly DataContext _context;

public class UpdateWorkflowOutcomeStateHandler : IRequestHandler<UpdateWorkflowOutcomeStateRequest, Result>
public UpdateWorkflowOutcomeStateHandler(DataContext context)
{
private readonly DataContext _context;
_context = context;
}

public UpdateWorkflowOutcomeStateHandler(DataContext context)
{
_context = context;
}
public async Task<Result> Handle(UpdateWorkflowOutcomeStateRequest request, CancellationToken cancellationToken)
{
// Retrieve the outcome from the database
var outcomeEntity = await _context.WorkflowOutcomeEntities
.FirstOrDefaultAsync(o => o.WorkflowOutcomeEntityId == request.WorkflowOutcomeId, cancellationToken);

public async Task<Result> Handle(UpdateWorkflowOutcomeStateRequest request, CancellationToken cancellationToken)
if (outcomeEntity is null)
{
// Retrieve the outcome from the database
var outcomeEntity = await _context.WorkflowOutcomeEntities
.FirstOrDefaultAsync(o => o.WorkflowOutcomeEntityId == request.WorkflowOutcomeId, cancellationToken);

if (outcomeEntity is null)
{
return Result.Fail("The specified outcome does not exist in the database.");
}
return Result.Fail("The specified outcome does not exist in the database.");
}

// Update the state
outcomeEntity.WorkflowOutcomeState = request.NewState;
// Update the state
outcomeEntity.WorkflowOutcomeState = request.NewState;

// Save changes to the database
await _context.SaveChangesAsync(cancellationToken);
// Save changes to the database
await _context.SaveChangesAsync(cancellationToken);

return Result.Ok();
}
return Result.Ok();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ public enum EWorkflowState
Inactive,
ActiveWithExternalTrigger,
ActiveWithRecurrentTrigger,
ActiveWithFormTrigger

}
Loading