Esempio n. 1
0
        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));
            }
        }
Esempio n. 2
0
        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));
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        public async Task <(bool Saved, PhraseologyCategory Phraseology)> SavePhraseologyCategory(PhraseologyCategoryDto phraseologyDto)
        {
            var phraseology = _mapper.Map <PhraseologyCategory>(phraseologyDto);

            _phraseologyCategoryRepository.Save(phraseology);

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