public async Task <UpdatePlayerResponse> Handle(UpdatePlayerRequest request, CancellationToken cancellationToken) { var query = new GetPlayerByIdQuery() { Id = request.playerId }; var gotPlayer = await this.queryExecutor.Execute(query); if (gotPlayer == null) { return new UpdatePlayerResponse() { Data = null } } ; var command = new UpdatePlayerCommand() { Parameter = this.mapper.Map(request, gotPlayer) }; var player = await this.commandExecutor.Execute(command); return(new UpdatePlayerResponse() { Data = this.mapper.Map <Domain.Models.Player>(player) }); } }
[HttpPut] // para criar é necessário receber um command e um handler public IEnumerable <Player.Domain.Entities.Player> Update( [FromBody] UpdatePlayerCommand command, [FromServices] PlayerHandler handler) { command.Name = "jean"; return((IEnumerable <Entities.Player>)(GenericCommandResult) handler.Handle(command)); }
public async Task <IActionResult> Update(int id, [FromBody] UpdatePlayerCommand command) { command.Id = id; await Mediator.Send(command); return(NoContent()); }
public async Task <IActionResult> Put([FromBody] UpdatePlayerCommand command) { var updatePlayerId = await _mediator.Send(command); if (updatePlayerId == Guid.Empty) { return(NotFound(command.Id)); } return(Ok(updatePlayerId)); }
public async Task <ActionResult> Put(int id, [FromBody] UpdatePlayerCommand command) { if (!ModelState.IsValid || id != command.Id) { return(BadRequest()); } await _mediator.Send(command); return(NoContent()); }
public async Task <ActionResult> Update(int id, UpdatePlayerCommand command) { if (id != command.Id) { return(BadRequest()); } await Mediator.Send(command); return(NoContent()); }
public void UpdatePlayer(UpdatePlayerCommand cmd) { var player = _context.Player.Find(cmd.Id); if (player == null) { throw new Exception("Unable to find the player"); } if (player.IsDeleted) { throw new Exception("Unable to update a deleted player"); } cmd.UpdatePlayer(player); _context.SaveChanges(); }
public ICommandResult Handle(UpdatePlayerCommand command) { command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "player não encontrdo", command.Name)); } //recuperar pelo id var player = _repository.GetById(command.Id, command.Name); player.UpdateName(command.Name); _repository.Update(player); return(new GenericCommandResult(true, "Jogador atualizado", player)); }
public async Task UpdatePlayerCommand_Can_Update_Player() { using (var dbContext = GetDbContext("UpdatePlayerCommand_Can_Update_Player")) { var fakeRepo = new PlayerRepository(dbContext); await fakeRepo.AddAsync(new Domain.Entities.Player { Name = "FirstName", Surname = "LastName", Height = 1.98, EmailAddress = "*****@*****.**" }); } using (var dbContext = GetDbContext("UpdatePlayerCommand_Can_Update_Player")) { var fakeRepo = new PlayerRepository(dbContext); var fakeLogger = new Mock <ILogger <UpdatePlayerCommandHandler> >(); var handler = new UpdatePlayerCommandHandler(fakeRepo, GetMapper(), fakeLogger.Object); var command = new UpdatePlayerCommand { Id = 1, Name = "NewName", Surname = "NewLastName", Height = 1.55, EmailAddress = "*****@*****.**" }; var result = await handler.Handle(command, default); Assert.False(result.Notifications.HasErrors()); Assert.Equal(command.Name, result.PlayerLookupModel.Name); Assert.Equal(command.Surname, result.PlayerLookupModel.Surname); Assert.Equal(command.Height, result.PlayerLookupModel.Height); Assert.Equal(command.EmailAddress, result.PlayerLookupModel.EmailAddress); } }
public ActionResult EditPlayer(UpdatePlayerCommand command) { HandleCommand(command, Json("Player added")); return(RedirectToAction("PlayersManage")); }
public async Task <ApiResponse> Update([FromRoute] int id, [FromBody] UpdatePlayerCommand command) { var response = await this._updatePlayerCommandHandler.Handle(command); return(this.BuildApiResponse(response)); }
public async Task <ActionResult <PlayerViewModel> > Update([FromBody] UpdatePlayerCommand updatePlayerCommand) { return(ResolveResult(await Mediator.Send(updatePlayerCommand))); }