public async Task <IActionResult> UpdatePhraseologyCategory([FromBody] PhraseologyCategoryDto PhraseologyCategoryDto) { try { if (ModelState.IsValid) { if (PhraseologyCategoryDto.Id == 0) { return(NotFound()); } var result = await _phraseologyCategoryService.UpdatePhraseologyCategory(PhraseologyCategoryDto); if (!result.Updated) { return(BadRequest($"Ocorreu um erro ao tentar atualizar a resposta com id {PhraseologyCategoryDto.Id}")); } return(Ok(result)); } else { return(BadRequest(ModelState)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> SavePhraseologyCategory([FromBody] PhraseologyCategoryDto PhraseologyCategoryDto) { try { if (ModelState.IsValid) { var result = await _phraseologyCategoryService.SavePhraseologyCategory(PhraseologyCategoryDto); if (!result.Saved) { return(BadRequest($"Ocorreu um erro ao tentar cadastrar um resposta")); } return(Ok(result)); } else { return(BadRequest(ModelState)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task SavePhraseologyCategory_ReturningTrueAndObject() { _mockUnitOfWork.Setup(x => x.CommitAsync()).ReturnsAsync(true); var phraseologyCategoryDto = new PhraseologyCategoryDto { Name = "test" }; var phraseologyCategoryService = new PhraseologyCategoryService(_mockPhraseologyCategoryRepository.Object, _mockUnitOfWork.Object, _mapper); var result = await phraseologyCategoryService.SavePhraseologyCategory(phraseologyCategoryDto); Assert.True(result.Saved); Assert.IsType <PhraseologyCategory>(result.Phraseology); Assert.Equal("test", result.Phraseology.Name); }
public async Task UpdatePhraseologyCategory_ReturningTrueAndObject() { _mockUnitOfWork.Setup(x => x.CommitAsync()).ReturnsAsync(true); _mockPhraseologyCategoryRepository.Setup(x => x.GetById(It.IsAny <int>())).ReturnsAsync(new PhraseologyCategory { Id = 1, Name = "teste2" }); var phraseologyCategoryDto = new PhraseologyCategoryDto { Id = 1, Name = "test1" }; var phraseologyCategoryService = new PhraseologyCategoryService(_mockPhraseologyCategoryRepository.Object, _mockUnitOfWork.Object, _mapper); var result = await phraseologyCategoryService.UpdatePhraseologyCategory(phraseologyCategoryDto); Assert.True(result.Updated); Assert.IsType <PhraseologyCategory>(result.Phraseology); Assert.Equal("test1", result.Phraseology.Name); }
public async Task <(bool Updated, PhraseologyCategory Phraseology)> UpdatePhraseologyCategory(PhraseologyCategoryDto phraseologyDto) { var phraseology = await _phraseologyCategoryRepository.GetById(phraseologyDto.Id); if (phraseology == null) { return(false, phraseology); } _mapper.Map(phraseologyDto, phraseology); return(await _unitOfWork.CommitAsync(), phraseology); }
public async Task <(bool Saved, PhraseologyCategory Phraseology)> SavePhraseologyCategory(PhraseologyCategoryDto phraseologyDto) { var phraseology = _mapper.Map <PhraseologyCategory>(phraseologyDto); _phraseologyCategoryRepository.Save(phraseology); return(await _unitOfWork.CommitAsync(), phraseology); }