public async Task <CustomerOutput> Execute(Guid customerId) { Customer customer = await _customerReadOnlyRepository.Get(customerId); if (customer == null) { throw new CustomerNotFoundException($"The customer {customerId} does not exists or is not processed yet."); } List <AccountOutput> accounts = new List <AccountOutput> (); foreach (Guid accountId in customer.Accounts.ToReadOnlyCollection()) { Account account = await _accountReadOnlyRepository.Get(accountId); if (account != null) { AccountOutput accountOutput = new AccountOutput(account); accounts.Add(accountOutput); } } CustomerOutput output = new CustomerOutput(customer, accounts); return(output); }
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); }
public async Task <CustomerResult> Get(Guid id) { var customer = await customerReadOnlyRepository.Get(id); CustomerResult customerResult = resultConverter.Map <CustomerResult>(customer); return(customerResult); }
public async Task <ScheduleResult> Process(UpdateScheduleCommand command) { Domain.Schedule.Schedule schedule = new Domain.Schedule.Schedule(command.ScheduleId, command.Day, command.Hour) { Customer = await customerReadOnlyRepository.Get(command.CustomerId), Service = await serviceReadOnlyRepository.Get(command.ServiceId) }; await scheduleWriteOnlyRepository.Update(schedule); ScheduleResult scheduleResult = resultConverter.Map <ScheduleResult>(schedule); return(scheduleResult); }
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); }
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); }
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); }
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); }
public async Task Proccess(Guid id) { var customer = await customerReadOnlyRepository.Get(id); await customerWriteOnlyRepository.Delete(customer); }