Пример #1
0
        public void performCreate(RequestBankTransferDto requestBankTransferDto)
        {
            Notification notification = this.validation(requestBankTransferDto);

            if (notification.hasErrors())
            {
                throw new ArgumentException(notification.errorMessage());
            }
            BankAccount originAccount      = _iUnitOfWork.BankAccounts.findByNumberLocked(requestBankTransferDto.fromAccountNumber);
            BankAccount destinationAccount = _iUnitOfWork.BankAccounts.findByNumberLocked(requestBankTransferDto.toAccountNumber);

            this.transferDomainService.performTransfer(originAccount, destinationAccount, requestBankTransferDto.amount);

            var idCustomer = originAccount.CustomerId;

            this._iUnitOfWork.BankAccounts.save(originAccount);
            this._iUnitOfWork.BankAccounts.save(destinationAccount);

            TransDetalle transDetalle = new TransDetalle()
            {
                customer_id    = idCustomer
                , numb_origen  = requestBankTransferDto.fromAccountNumber
                , numb_destino = requestBankTransferDto.toAccountNumber
                , fecha        = DateTime.Now
                , monto        = requestBankTransferDto.amount
            };

            this._iUnitOfWork.Transactions.Add(transDetalle);

            this._iUnitOfWork.Complete();
        }
 private Notification.Notification validation(RequestBankTransferDto requestBankTransferDto)
 {
     Notification.Notification notification = new Notification.Notification();
     if (requestBankTransferDto == null || requestBankTransferDto.getRequestBodyType() == RequestBodyType.INVALID)
     {
         notification.addError("Invalid JSON data in request body.");
     }
     return(notification);
 }
        public void performTransfer(RequestBankTransferDto requestBankTransferDto,
                                    Func <string, BankAccount> delagatefindByNumberLocked, Action <BankAccount> delegateUpdate)
        {
            Notification.Notification notification = this.validation(requestBankTransferDto);
            if (notification.hasErrors())
            {
                throw new ArgumentException(notification.errorMessage());
            }
            BankAccount originAccount      = delagatefindByNumberLocked(requestBankTransferDto.fromAccountNumber);
            BankAccount destinationAccount = delagatefindByNumberLocked(requestBankTransferDto.toAccountNumber);

            this.transferDomainService.performTransfer(originAccount, destinationAccount, requestBankTransferDto.amount);
            delegateUpdate(originAccount);
            delegateUpdate(destinationAccount);
        }
Пример #4
0
 public IActionResult Post([FromBody] RequestBankTransferDto requestBankTransferDto)
 {
     try
     {
         _transactionApplicationService.performCreate(requestBankTransferDto);
         return(Ok(this.responseHandler.getOkCommandResponse("Transfer done!", Constantes.HttpStatus.Success)));
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(this.responseHandler.getAppCustomErrorResponse(ex.Message)));
     }
     catch (Exception ex)
     {
         return(StatusCode(Constantes.HttpStatus.ErrorServer, this.responseHandler.getAppExceptionResponse()));
     }
 }
 public IHttpActionResult performTransfer([FromBody] RequestBankTransferDto requestBankTransferDto)
 {
     try
     {
         Func <string, BankAccount> delagatefindByNumberLocked = findByNumberLocked;
         Action <BankAccount>       delegateUpdate             = update;
         transactionApplicationService.performTransfer(requestBankTransferDto, delagatefindByNumberLocked, delegateUpdate);
         return(Json(this.responseHandler.getOkCommandResponse("Transfer done!")));
     }
     catch (ArgumentException ex)
     {
         return(Json(this.responseHandler.getAppCustomErrorResponse(ex.Message)));
     }
     catch (Exception ex)
     {
         return(Json(this.responseHandler.getAppExceptionResponse()));
     }
 }