public async Task <ActionResult> Put([FromBody] LoanedGameUpdateViewModel model) { model.Validate(); if (model.Invalid) { return(BadRequest(new ResultViewModel { Success = false, Message = "Não foi possível atualizar o empréstimo jogo", Data = model.Notifications })); } var result = await _service.Put(model); return(Ok(result)); }
public async Task <ResultViewModel> Put(LoanedGameUpdateViewModel loanedGame) { var entity = _mapper.Map <LoanedGame>(loanedGame); var entityDB = await _repository.GetByIdWithRelationshipsAsync(loanedGame.Id); if (loanedGame.Returned && !entityDB.Returned) { entityDB.Game.Available = true; await _repositoryGame.UpdateAsync(entityDB.Game); } var result = await _repository.UpdateAsync(entity); return(new ResultViewModel { Success = true, Message = "empréstimo de jogo modificado.", Data = _mapper.Map <LoanedGameViewModel>(result) }); }