public async Task Process(GetAccountDetailsInput input)
        {
            var account = await accountReadOnlyRepository.Get(input.AccountId);

            if (account == null)
            {
                outputBoundary.Populate(null);
                return;
            }

            AccountOutput output = outputConverter.Map <AccountOutput>(account);

            outputBoundary.Populate(output);
        }
Ejemplo n.º 2
0
        public async Task Process(GetBasketDetailsInput input)
        {
            var basket = await basketReadOnlyRepository.Get(input.BasketId);

            if (basket == null)
            {
                outputBoundary.Populate(null);
                return;
            }

            BasketOutput output = outputConverter.Map <BasketOutput>(basket);

            outputBoundary.Populate(output);
        }
        public async Task Handle(GetAccountDetailsCommand message)
        {
            var customer = await customerReadOnlyRepository.GetByAccount(message.AccountId);

            if (customer == null)
            {
                outputBoundary.Populate(null);
                return;
            }

            var             account  = customer.FindAccount(message.AccountId);
            AccountResponse response = responseConverter.Map <AccountResponse>(account);

            outputBoundary.Populate(response);
        }
Ejemplo n.º 4
0
        public async Task Process(GetCustomerDetailsInput input)
        {
            Customer customer = await customerReadOnlyRepository.Get(input.CustomerId);

            if (customer == null)
            {
                throw new CustomerNotFoundException($"The customer {input.CustomerId} does not exist or it was not processed yet.");
            }

            List <Order> orders = await orderReadOnlyRepository.GetByCustomer(input.CustomerId);

            List <OrderOutput> orderOutputs = new List <OrderOutput>();

            if (orders.Count == 0)
            {
                throw new CustomerNotFoundException($"No order found for customer {input.CustomerId}.");
            }
            else
            {
                foreach (var item in orders)
                {
                    OrderOutput orderOutput = outputConverter.Map <OrderOutput>(item);
                    orderOutputs.Add(orderOutput);
                }
            }


            CustomerOutput output = outputConverter.Map <CustomerOutput>(customer);

            output = new CustomerOutput(customer.Id, customer.PIN.Text, customer.Name.Text, orderOutputs);

            outputBoundary.Populate(output);
        }
Ejemplo n.º 5
0
        public async Task Process(Input input)
        {
            Order order = await orderReadOnlyRepository.Get(input.OrderId);

            TrackingOutput output = outputConverter.Map <TrackingOutput>(order);

            outputBoundary.Populate(output);
        }
Ejemplo n.º 6
0
        public async Task Handle(GetCustomerDetaisCommand message)
        {
            Domain.Customers.Customer customer = await this.customerReadOnlyRepository.Get(message.CustomerId);

            CustomerResponse response = responseConverter.Map <CustomerResponse>(customer);

            outputBoundary.Populate(response);
        }
        public async System.Threading.Tasks.Task Execute()
        {
            var allTasks = await _taskRepository.GetAll();

            var tasksDto = _outputConverter.Map <List <TaskDto> >(allTasks);

            _outputBoundary.Populate(tasksDto);
        }
        public void Process(Input input)
        {
            cajuService.Run(input);

            RunOutput output = outputConverter.Map <RunOutput>(input);

            outputBoundary.Populate(output);
        }
Ejemplo n.º 9
0
        public async Task Process(ListBooksInput input)
        {
            var books = bookReadOnlyRepository.Select();

            var             booksOutput = books.Select(book => outputConverter.Map <BookOutput>(book));
            ListBooksOutput output      = new ListBooksOutput(booksOutput);

            outputBoundary.Populate(output);
        }
Ejemplo n.º 10
0
        public async Task Process(RegisterInput input)
        {
            Customer customer = new Customer(input.PIN, input.Name);

            await customerWriteOnlyRepository.Add(customer);

            CustomerOutput customerOutput = outputConverter.Map <CustomerOutput>(customer);

            RegisterOutput output = new RegisterOutput(customerOutput);

            outputBoundary.Populate(output);
        }
Ejemplo n.º 11
0
        public async Task Process(GetAccountDetailsInput input)
        {
            Account account = await accountReadOnlyRepository.Get(input.AccountId);

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

            AccountOutput output = outputConverter.Map <AccountOutput>(account);

            outputBoundary.Populate(output);
        }
Ejemplo n.º 12
0
        public async Task Handle(RegisterCommand message)
        {
            Customer customer = new Customer(new PIN(message.PIN), new Name(message.Name));

            Account account = new Account();
            Credit  credit  = new Credit(new Amount(message.InitialAmount));

            account.Deposit(credit);

            customer.Register(account);

            await customerWriteOnlyRepository.Add(customer);

            CustomerResponse customerResponse = responseConverter.Map <CustomerResponse>(customer);
            AccountResponse  accountResponse  = responseConverter.Map <AccountResponse>(account);
            RegisterResponse response         = new RegisterResponse(customerResponse, accountResponse);

            outputBoundary.Populate(response);
        }
Ejemplo n.º 13
0
        public async Task Process(DepositInput input)
        {
            Account account = await accountReadOnlyRepository.Get(input.AccountId);

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

            Credit credit = new Credit(account.Id, input.Amount);

            account.Deposit(credit);

            await accountWriteOnlyRepository.Update(account, credit);

            TransactionOutput transactionResponse = outputConverter.Map <TransactionOutput>(credit);
            DepositOutput     output = new DepositOutput(transactionResponse, account.GetCurrentBalance().Value);

            outputBoundary.Populate(output);
        }
Ejemplo n.º 14
0
        public async Task Process(AddBasketInput input)
        {
            Customer customer = await customerReadOnlyRepository.Get(input.CustomerId);

            if (customer == null)
            {
                throw new CustomerNotFoundException($"The customer {input.CustomerId} does not exist or it was not processed yet.");
            }

            Basket basket = new Basket(customer.Id);

            await basketWriteOnlyRepository.Add(basket);

            CustomerOutput customerOutput = outputConverter.Map <CustomerOutput>(customer);
            BasketOutput   basketOutput   = outputConverter.Map <BasketOutput>(basket);

            AddBasketOutput output = new AddBasketOutput(customerOutput, basketOutput);

            outputBoundary.Populate(output);
        }
Ejemplo n.º 15
0
        public async Task Process(RegisterInput message)
        {
            Customer customer = new Customer(message.PIN, message.Name);

            Account account = new Account();

            account.Open(customer.Id, new Credit(account.Id, message.InitialAmount));
            customer.Register(account.Id);

            var customerEvents = customer.GetEvents();
            var accountEvents  = account.GetEvents();

            await bus.Publish(customerEvents);

            await bus.Publish(accountEvents);

            //
            // To ensure the Customer and Account are created in the database
            // we wait for the records be available in the following queries
            // with retry
            //

            bool consumerReady = await RetryGet(async() => await customerReadOnlyRepository.Get(customer.Id)) &&
                                 await RetryGet(async() => await accountReadOnlyRepository.Get(account.Id));

            if (!consumerReady)
            {
                customer = null;
                account  = null;

                //
                // TODO: Throw exception, monitor the inconsistencies and fail fast.
                //
            }

            CustomerOutput customerOutput = responseConverter.Map <CustomerOutput>(customer);
            AccountOutput  accountOutput  = responseConverter.Map <AccountOutput>(account);
            RegisterOutput output         = new RegisterOutput(customerOutput, accountOutput);

            outputBoundary.Populate(output);
        }
Ejemplo n.º 16
0
        public async Task Process(RegisterInput input)
        {
            Customer customer = new Customer(input.PIN, input.Name);

            Account account = new Account(customer.Id);
            Credit  credit  = new Credit(account.Id, input.InitialAmount);

            account.Deposit(credit);

            customer.Register(account.Id);

            await customerWriteOnlyRepository.Add(customer);

            await accountWriteOnlyRepository.Add(account, credit);

            CustomerOutput customerOutput = outputConverter.Map <CustomerOutput>(customer);
            AccountOutput  accountOutput  = outputConverter.Map <AccountOutput>(account);
            RegisterOutput output         = new RegisterOutput(customerOutput, accountOutput);

            outputBoundary.Populate(output);
        }
        public async Task Process(CreateBookInput input)
        {
            Book book = bookReadOnlyRepository.Select(input.Isbn);

            if (book != null)
            {
                throw new BookAlreadyExistsException($"The book {input.Isbn} already exists.");
            }

            Book newNook = new Book(
                input.BookName,
                input.Isbn,
                input.Author,
                input.Price);

            bookWriteOnlyRepository.Insert(newNook);

            var output = outputConverter.Map <BookOutput>(newNook);

            outputBoundary.Populate(output);
        }
Ejemplo n.º 18
0
        public async Task Process(WithdrawInput input)
        {
            Account account = await accountReadOnlyRepository.Get(input.AccountId);

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

            Debit debit = new Debit(account.Id, input.Amount);

            account.Withdraw(debit);

            var domainEvents = account.GetEvents();
            await bus.Publish(domainEvents);

            TransactionOutput transactionOutput = responseConverter.Map <TransactionOutput>(debit);
            WithdrawOutput    output            = new WithdrawOutput(transactionOutput, account.GetCurrentBalance().Value);

            outputBoundary.Populate(output);
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
        public void Process(Input input)
        {
            HexagonalTemplate order = new HexagonalTemplate(
                input.Name,
                input.UseCases,
                input.UserInterface,
                input.DataAccess,
                input.Tips,
                input.SkipRestore);

            bus.Publish(order);

            trackingService.OrderReceived(
                order.Id,
                order.Name.Text,
                order.CommandLines);

            OrderOutput generateOutput = outputConverter.Map <OrderOutput>(order);

            outputBoundary.Populate(generateOutput);
        }
Ejemplo n.º 21
0
        public async Task Process(GetCustomerDetailsInput input)
        {
            //
            // TODO: The following queries could be simplified
            //

            Customer customer = await customerReadOnlyRepository.Get(input.CustomerId);

            if (customer == null)
            {
                throw new CustomerNotFoundException($"The customer {input.CustomerId} does not exists or is not processed yet.");
            }

            List <AccountOutput> accounts = new List <AccountOutput>();

            foreach (var accountId in customer.Accounts)
            {
                Account account = await accountReadOnlyRepository.Get(accountId);

                //
                // TODO: The "Accout closed state" is not propagating to the Customer Aggregate
                //

                if (account != null)
                {
                    AccountOutput accountOutput = outputConverter.Map <AccountOutput>(account);
                    accounts.Add(accountOutput);
                }
            }

            CustomerOutput output = outputConverter.Map <CustomerOutput>(customer);

            output = new CustomerOutput(
                customer.Id,
                customer.PIN.Text,
                customer.Name.Text,
                accounts);

            outputBoundary.Populate(output);
        }
Ejemplo n.º 22
0
        public async Task Process(RemoveBookInput input)
        {
            Book book = await bookReadOnlyRepository.Get(input.BookId);

            if (book == null)
            {
                throw new BookNotFoundException($"The book {input.BookId} does not exist.");
            }

            Basket basket = (input.BasketId != null)? await basketReadOnlyRepository.Get(input.BasketId):new Basket();

            Removal removal = new Removal(book.Id);

            basket.RemoveBook(removal);

            await basketWriteOnlyRepository.Update(basket);

            OrderOutput      orderResponse = outputConverter.Map <OrderOutput>(removal);
            RemoveBookOutput output        = new RemoveBookOutput(orderResponse, basket.GetTotalPrice().Value);

            outputBoundary.Populate(output);
        }
Ejemplo n.º 23
0
        public async Task Process(CheckoutInput input)
        {
            Customer customer = await customerReadOnlyRepository.Get(input.CustomerId);

            if (customer == null)
            {
                throw new CustomerNotFoundException($"The customer {input.CustomerId} does not exist or it was not processed yet.");
            }

            Basket basket = await basketReadOnlyRepository.Get(input.BasketId);

            if (basket == null)
            {
                throw new BasketNotFoundException($"The basket {input.BasketId} does not exist or it was already deleted.");
            }

            CustomerOutput customerOutput = outputConverter.Map <CustomerOutput>(customer);
            BasketOutput   basketOutput   = outputConverter.Map <BasketOutput>(basket);

            CheckoutOutput output = new CheckoutOutput(customerOutput, basketOutput, input.OrderDate, basket.GetTotalPrice().Value);

            outputBoundary.Populate(output);
        }
Ejemplo n.º 24
0
        public async Task Process(WithdrawInput input)
        {
            Account account = await accountReadOnlyRepository.Get(input.AccountId);

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

            Debit debit = new Debit(new Amount(input.Amount));

            account.Withdraw(debit);

            await accountWriteOnlyRepository.Update(account);

            TransactionOutput transactionOutput = outputConverter.Map <TransactionOutput>(debit);
            WithdrawOutput    output            = new WithdrawOutput(
                transactionOutput,
                account.GetCurrentBalance().Value
                );

            outputBoundary.Populate(output);
        }
Ejemplo n.º 25
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);
        }