Exemplo n.º 1
0
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                var deleteEndereco = await _service.Delete(id);

                return(Ok(deleteEndereco));
            }
            catch (NotFoundException e)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound, $"{e.Message}"));
            }
            catch (ArgumentException e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"{e.Message}"));
            }
        }
Exemplo n.º 2
0
        // DELETAR
        public async Task <PessoaDto> Delete(int id)
        {
            var pessoa = await _repo.GetByIdAsync(id);

            if (pessoa == null)
            {
                throw new NotFoundException("Nenhuma pessoa encontrada com esse id");
            }

            _repo.Delete(pessoa);
            if (await _repo.SaveAsync())
            {
                await _enderecoService.Delete(pessoa.EnderecoId);

                return(_map.Map <PessoaDto>(pessoa));
            }
            throw new ArgumentException("Erro ao persistir dados!");
        }