Exemple #1
0
        public IActionResult CriarPet([FromBody] PetRequestDTO petDto)
        {
            var categoria = petRepository.ObterCategoriaPorId(petDto.IdCategoria);

            if (categoria == null)
            {
                return(BadRequest("A categoria é obrigatoria"));
            }

            var pet = new Pet(petDto.Nome, petDto.Status, categoria,
                              petDto.Tags.Select(tag => new Tag(tag)).ToList());

            var petCadastrado = petRepository.Cadastrar(pet);

            contexto.SaveChanges();

            return(CreatedAtRoute("GetPet", new { id = petCadastrado.Id }, petCadastrado));
        }