Exemple #1
0
        public Task <CommandResult> Handle(UpdateChequeCommand command, CancellationToken cancellationToken)
        {
            if (!command.IsValid())
            {
                NotifyCommandErrors(command);
                return(Response());
            }

            if (_chequeRepository.CheckNumeroChequeExists(command.NumeroCheque, command.ClienteId, command.BancoId, command.Id))
            {
                NotifyCommandError(RequestErrorsMessageConstants.ChequeAlreadyExists);
                return(Response());
            }

            Banco   banco   = _bancoRepository.GetById(command.BancoId, loadRelatedData: false);
            Cliente cliente = _clienteRepository.GetById(command.ClienteId, loadRelatedData: false);
            Cheque  cheque  = new Cheque(command.Id, banco, command.Agencia, command.Conta, command.NumeroCheque, cliente, command.DataEmissao, command.DataVencimento, command.Valor);

            _chequeRepository.Update(cheque);

            if (Commit())
            {
                _mediator.Publish(new UpdatedChequeEvent());
            }

            return(Response());
        }
Exemple #2
0
        public HttpResponseMessage Put(int id, [FromBody] ChequeRequest cheque)
        {
            if (string.IsNullOrEmpty(cheque.LastName) || string.IsNullOrEmpty(cheque.FirstName))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new BaseApiResponse
                {
                    Code = InternalApiStatusCode.FailedRequestValidation,
                    Message = "Invalid cheque object"
                }));
            }

            var chequeResposne = new ChequeResponse();

            try
            {
                var chequeResult = _chequeRepository.Update(new ChequeDto
                {
                    ChequeId  = id,
                    LastName  = cheque.LastName,
                    FirstName = cheque.FirstName,
                    Amount    = cheque.Amount,
                });

                if (chequeResult == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, new BaseApiResponse
                    {
                        Code = InternalApiStatusCode.Error,
                        Message = "cheque is not found"
                    }));
                }

                chequeResposne.Cheque  = chequeResult;
                chequeResposne.Code    = InternalApiStatusCode.Success;
                chequeResposne.Message = "cheque is updated";

                return(Request.CreateResponse(HttpStatusCode.OK, chequeResposne));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
 public void UpdateCheques(Cheque cheque) => _chequeRepository.Update(cheque);