-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from bsandmann/dev
Dev
- Loading branch information
Showing
10 changed files
with
1,189 additions
and
718 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
...low.Core/Commands/WorkflowOutcome/GetWorkflowOutcomeById/GetWorkflowOutcomeByIdHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 25 additions & 26 deletions
51
...mands/WorkflowOutcome/GetWorkflowOutcomeIdsByState/GetWorkflowOutcomeIdsByStateHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
49 changes: 24 additions & 25 deletions
49
.../Commands/WorkflowOutcome/UpdateWorkflowOutcomeState/UpdateWorkflowOutcomeStateHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.