public async Task Handle_PatchEntityFromModelCommand_Test() { using (var scope = this.provider.CreateScope()) { var mediator = scope.ServiceProvider.GetRequiredService <IMediator>(); var delta = new Delta <Model>(); var request = new PatchEntityFromModelCommand <Model, Entity, int, EntityDbContext>(delta); var result = await mediator.HandleAsync(request, default); Assert.NotNull(result); } }
public async Task <IActionResult> PatchAsync(int id, [FromBody] Delta <UpdateToDoListModel> model, CancellationToken cancellationToken = default) { if (!model.TryGetPropertyValue(nameof(UpdateToDoListModel.Id), out object idValue) || !(idValue is int modelId) || (id != modelId)) { return(this.BadRequest("ToDoList ID is different in the route and the model")); } var request = new PatchEntityFromModelCommand <UpdateToDoListModel, ToDoList, int, EntityDbContext>(model); var result = await mediator.HandleAsync(request, cancellationToken); if (!result.IsSuccess) { var problemDetails = new ProblemDetails(); problemDetails.Extensions.Add(nameof(Reason), result.Reasons); return(new BadRequestObjectResult(problemDetails)); } return(this.Ok(new IdModel <int> { Id = result.Value })); }