Beispiel #1
0
        public void ShouldUpdateCustomer()
        {
            var model = customerReadOnlyRepository.GetById(idCustomer);

            model.Should().NotBeNull();
            var newModel = CustomerBuilder.New().WithId(model.Id).WithName("NewCustomer").Build();

            customerWriteOnlyRepository.Update(newModel);
        }
Beispiel #2
0
        public async Task <CustomerResult> Process(UpdateCustomerCommand command)
        {
            Domain.Customers.Customer customer = new Domain.Customers.Customer(command.CustomerId, command.Name, command.LastName, command.Document, command.Celphone, command.Address);

            await customerWriteOnlyRepository.Update(customer);

            CustomerResult customerResult = resultConverter.Map <CustomerResult>(customer);

            return(customerResult);
        }
Beispiel #3
0
        public async Task <CloseResult> Handle(CloseCommand command)
        {
            Customer customer = await customerReadOnlyRepository.GetByAccount(command.AccountId);

            Account account = customer.FindAccount(command.AccountId);

            customer.RemoveAccount(command.AccountId);
            await customerWriteOnlyRepository.Update(customer);

            CloseResult response = resultConverter.Map <CloseResult>(account);

            return(response);
        }
Beispiel #4
0
        public async Task Handle(CloseCommand request)
        {
            Customer customer = await customerReadOnlyRepository.GetByAccount(request.AccountId);

            Account account = customer.FindAccount(request.AccountId);

            customer.RemoveAccount(request.AccountId);
            await customerWriteOnlyRepository.Update(customer);

            CloseResponse response = responseConverter.Map <CloseResponse>(account);

            this.outputBoundary.Populate(response);
        }
Beispiel #5
0
        public async Task Handle(DepositCommand command)
        {
            Customer customer = await customerReadOnlyRepository.GetByAccount(command.AccountId);

            if (customer == null)
            {
                throw new AccountNotFoundException($"The account {command.AccountId} does not exists or is already closed.");
            }

            Credit  credit  = new Credit(new Amount(command.Amount));
            Account account = customer.FindAccount(command.AccountId);

            account.Deposit(credit);

            await customerWriteOnlyRepository.Update(customer);

            TransactionResponse transactionResponse = responseConverter.Map <TransactionResponse>(credit);
            DepositResponse     response            = new DepositResponse(transactionResponse, account.CurrentBalance.Value);

            outputBoundary.Populate(response);
        }
Beispiel #6
0
        public async Task <DepositResult> Process(DepositCommand command)
        {
            Customer customer = await customerReadOnlyRepository.GetByAccount(command.AccountId);

            if (customer == null)
            {
                throw new AccountNotFoundException($"The account {command.AccountId} does not exists or is already closed.");
            }

            Credit  credit  = new Credit(new Amount(command.Amount));
            Account account = customer.FindAccount(command.AccountId);

            account.Deposit(credit);

            await customerWriteOnlyRepository.Update(customer);

            TransactionResult transactionResult = resultConverter.Map <TransactionResult>(credit);
            DepositResult     response          = new DepositResult(transactionResult, account.CurrentBalance.Value);

            return(response);
        }
Beispiel #7
0
        public async Task Handle(WithdrawCommand request)
        {
            Customer customer = await customerReadOnlyRepository.GetByAccount(request.AccountId);

            if (customer == null)
            {
                throw new AccountNotFoundException($"The account {request.AccountId} does not exists or is already closed.");
            }

            Debit   debit   = new Debit(new Amount(request.Amount));
            Account account = customer.FindAccount(request.AccountId);

            account.Withdraw(debit);

            await customerWriteOnlyRepository.Update(customer);

            TransactionResponse transactionResponse = responseConverter.Map <TransactionResponse>(debit);
            WithdrawResponse    response            = new WithdrawResponse(
                transactionResponse,
                account.CurrentBalance.Value
                );

            outputBoundary.Populate(response);
        }