public async Task <IActionResult> SavePhraseology([FromBody] PhraseologyDto PhraseologyDto)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var result = await _phraseologyService.SavePhraseology(PhraseologyDto);

                    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 <IActionResult> UpdatePhraseology([FromBody] PhraseologyDto PhraseologyDto)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (PhraseologyDto.Id == 0)
                    {
                        return(NotFound());
                    }

                    var result = await _phraseologyService.UpdatePhraseology(PhraseologyDto);

                    if (!result.Updated)
                    {
                        return(BadRequest($"Ocorreu um erro ao tentar atualizar a resposta com id {PhraseologyDto.Id}"));
                    }

                    return(Ok(result));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task UpdatePhraseologyCategory_ReturningTrueAndObject()
        {
            _mockUnitOfWork.Setup(x => x.CommitAsync()).ReturnsAsync(true);
            _mockPhraseologyRepository.Setup(x => x.GetById(It.IsAny <int>())).ReturnsAsync(new Phraseology {
                Id = 1, Answer = "test phraseologyDto 1", PhraseologyTypeSubject = new PhraseologyTypeSubject {
                    Id = 1, Description = "teste PhraseologyTypeSubject 1"
                }
            });
            var phraseologyDto = new PhraseologyDto {
                Answer = "test phraseologyDto 2", PhraseologyTypeSubjectId = 1
            };

            _mockPhraseologyTypeSubjectRepository.Setup(x => x.GetById(It.IsAny <int>())).ReturnsAsync(new PhraseologyTypeSubject {
                Id = 1, Description = "teste PhraseologyTypeSubject 2"
            });

            var phraseologyService = new PhraseologyService(_mockPhraseologyRepository.Object, _mockPhraseologyTypeSubjectRepository.Object, _mockUnitOfWork.Object, _mapper);

            var result = await phraseologyService.UpdatePhraseology(phraseologyDto);

            Assert.True(result.Updated);
            Assert.IsType <Phraseology>(result.Phraseology);
            Assert.Equal("test phraseologyDto 2", result.Phraseology.Answer);
            Assert.Equal("teste PhraseologyTypeSubject 2", result.Phraseology.PhraseologyTypeSubject.Description);
        }
Exemple #4
0
        public async Task <(bool Saved, Phraseology Phraseology)> SavePhraseology(PhraseologyDto phraseologyDto)
        {
            var phraseology            = new Phraseology();
            var phraseologyTypeSubject = await _phraseologyTypeSubjectRepository.GetById(phraseologyDto.PhraseologyTypeSubjectId);

            if (phraseologyTypeSubject == null)
            {
                return(false, phraseology);
            }

            phraseology = _mapper.Map(phraseologyDto, phraseology);
            phraseology.PhraseologyTypeSubject = phraseologyTypeSubject;

            _phraseologyRepository.Save(phraseology);

            return(await _unitOfWork.CommitAsync(), phraseology);
        }
Exemple #5
0
        public async Task <(bool Updated, Phraseology Phraseology)> UpdatePhraseology(PhraseologyDto phraseologyDto)
        {
            var phraseology = await _phraseologyRepository.GetById(phraseologyDto.Id);

            var phraseologyTypeSubject = await _phraseologyTypeSubjectRepository.GetById(phraseologyDto.PhraseologyTypeSubjectId);

            if (phraseologyTypeSubject == null || phraseology == null)
            {
                return(false, phraseology);
            }

            _mapper.Map(phraseologyDto, phraseology);
            phraseology.PhraseologyTypeSubject = phraseologyTypeSubject;

            return(await _unitOfWork.CommitAsync(), phraseology);
        }