Exemple #1
0
        public async Task Handle_UpdateEntityFromModelCommand_Test()
        {
            using (var scope = this.provider.CreateScope())
            {
                var mediator = scope.ServiceProvider.GetRequiredService <IMediator>();
                var model    = new Model();
                var request  = new UpdateEntityFromModelCommand <Model, Entity, int, EntityDbContext>(model);
                var result   = await mediator.HandleAsync(request, default);

                Assert.NotNull(result);
            }
        }
Exemple #2
0
        public async Task <IActionResult> PutAsync(int id, [FromBody] UpdateToDoListModel model, CancellationToken cancellationToken = default)
        {
            if (id != model.Id)
            {
                return(this.BadRequest("ToDoList ID is different in the route and the model"));
            }

            var request = new UpdateEntityFromModelCommand <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
            }));
        }