public CharacterEntity Map(UpdateCharacterCommand source, CharacterEntity destination) { destination.Name = source.Name; destination.Description = source.Description; destination.PartsAsString = JsonConvert.SerializeObject(source.Parts); return(destination); }
public async Task <IActionResult> Put(int id, [FromBody] UpdateCharacterCommand command) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != command.Id) { ModelState.AddModelError("Id", "The id property must be equal to id param."); return(BadRequest(ModelState)); } try { var character = await Mediator.Send(new GetCharacterByIdQuery() { Id = id }); if (character == null) { return(NotFound()); } await Mediator.Send(command); return(Ok()); } catch (Exception) { return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }
public async void Update([FromBody] JsonElement item) { var command = new UpdateCharacterCommand(); command.Item = JsonConvert.DeserializeObject <CharacterItemDTO>(item.GetRawText()); var result = await _mediator.Send(command); }
public async Task <IResponse> Handle(UpdateCharacterCommand command) { command.Validate(); if (command.Invalid) { return(new GenericCommandResponse(false, "Comando Inválido", command.Notifications)); } var houseIsValid = await _potterService.ValidateHouse(command.House); if (!houseIsValid) { return(new GenericCommandResponse(false, "Comando Inválido", new Notification("House", "Casa não encontrada"))); } var character = await _characterRepository.GetById(command.Id); if (character == null) { return(new GenericCommandResponse(false, "Comando Inválido", new Notification("Id", "Personagem não encontrada"))); } character.Update(command.Name, command.Role, command.School, command.House, command.Patronus); await _characterRepository.Update(character); return(new GenericCommandResponse(true, "OK", character)); }
public Option <SuccessResult, ErrorResult> Update(UpdateCharacterCommand command) { return(_updateCharacterCommandValidator .Validate(command) .OnSuccess(errorBuilder => { var option = _characterRepository.GetById(command); option.MatchSome(x => _characterRepository.Update(_mapper.Map(command, x))); option.MatchNone(errorBuilder.AddRecordNotFound); })); }
public async Task <ApiResponse> Update(Guid id, UpdateCharacterDto request) { var command = new UpdateCharacterCommand { Id = id, Name = request.Name, Class = request.Class }; await _operationMediator.HandleAsync(command); return(ApiResponse.Ok()); }
public async void Updates_Character() { var request = new UpdateCharacterCommand() { Id = 1, Firstname = "Dean" }; var sut = new UpdateCharacterCommand.UpdateCharacterHandler(_context, _mapper, _userService, _gameService); var result = await sut.Handle(request, CancellationToken.None); _context.Biography.First(x => x.Id == request.Id).Firstname.ShouldBe("Dean"); result.ShouldBe(UpdateCharacterResponse.Updated); }
public async void CreateCharacterIfNotExist() { var numberOfCharactersAtStartOfTest = _context.Biography.Count(); var request = new UpdateCharacterCommand() { Id = 1000, Firstname = "Weasley", Surname = "Crusher", TypeId = _context.BiographyTypes.First(x => x.Name == StaticValues.BioTypePlayer).Id }; var sut = new UpdateCharacterCommand.UpdateCharacterHandler(_context, _mapper, _userService, _gameService); var result = await sut.Handle(request, CancellationToken.None); var numberOfCharactersAtEndOfTest = _context.Biography.Count(); numberOfCharactersAtEndOfTest.ShouldBeGreaterThan(numberOfCharactersAtStartOfTest); result.ShouldBe(UpdateCharacterResponse.Created); var newCharacter = _context.Biography.Last(); newCharacter.PlayerId.ShouldNotBe(0); newCharacter.StateId.ShouldNotBe(0); _context.BiographyTypes.First(x => x.Name == StaticValues.BioTypePlayer).Id.ShouldBe(newCharacter.TypeId.Value); }
public async Task <GenericCommandResponse> Update([FromBody] UpdateCharacterCommand command, [FromServices] CharacterHandler handler) { return((GenericCommandResponse)await handler.Handle(command)); }
public CharacterEntity Map(UpdateCharacterCommand source, CharacterEntity destination) { destination.Name = source.Name; destination.Description = source.Description; return(destination); }
protected override void OnInitialized() { this.characterUpdateModel = this.Character.To <UpdateCharacterCommand>(); }