예제 #1
0
        public async Task <IActionResult> Delete(DeletePessoaRequestDTO request)
        {
            if (ModelState.IsValid)
            {
                var result = await _mediator.Send(request);

                if (result.IsValid)
                {
                    return(Ok(result.IsValid));
                }
                else
                {
                    return(BadRequest(result.Errors));
                }
            }
            return(BadRequest(ModelState.IsValid));
        }
예제 #2
0
        public async Task <Result> Handle(DeletePessoaRequestDTO request, CancellationToken cancellationToken)
        {
            try
            {
                //Faz a validação dos parâmetros de entrada
                DeletePessoaCommandValidator validator = new DeletePessoaCommandValidator();
                var validate = validator.Validate(request);

                if (validate.IsValid)
                {
                    ActionResult.IsValid = await _service.Delete(request.IdPessoa);

                    if (!ActionResult.IsValid)
                    {
                        ActionResult.Errors = new Error()
                        {
                            Code    = ErrorCode.ERROR_RECORD_NOT_FOUND.GetCode(),
                            Message = ErrorCode.ERROR_RECORD_NOT_FOUND.GetAttributeDescription()
                        };
                    }
                }
                else
                {
                    return(GenerateModelError(ActionResult, validate.Errors));
                }
            }
            catch (Exception ex)
            {
                ActionResult.Errors = new Error()
                {
                    Code    = ErrorCode.EXCEPTION_ERROR.GetCode(),
                    Message = ex.InnerException.Message
                };
            }

            return(await Task.FromResult(ActionResult));
        }