private async void Handle(MessagePackage <CustomerDTO> message) { var customer = message.Entity; try { var service = serviceFunc(); var repo = repoFunc(); var request = new GetShoppingCartByCustomerRequest(customer.AnonymousId); var response = await service.GetCartAsync(request); var cart = await repo.GetCartByIdAsync(response.ShoppingCart.Id); cart.UpdateCustomer(customer.AnonymousId, customer.Id); await repo.SaveAsync(cart); //TODO change the order after debugging is completed await this.Complete(message.Message); } catch (Exception ex) { await base.Abandon(message.Message); } }
public async Task <GetShoppingCartResponse> GetCartAsync(GetShoppingCartByCustomerRequest request) { var cart = await repo.GetCartByCustomerAsync(request.CustomerId); if (cart == null) { cart = Domain.ShoppingCart.Create(request.CustomerId); await repo.SaveAsync(cart); } return(GetCartDTO(cart)); }
public async Task Consume(ConsumeContext <ICustomerCreatedNotification> context) { var customer = context.Message.Customer; var request = new GetShoppingCartByCustomerRequest(customer.AnonymousId); //either get an existing cart or create a new one var cartDTO = await builder.GetCartAsync(request); var cart = await repo.GetCartByIdAsync(cartDTO.Id); cart.UpdateCustomer(customer.AnonymousId, customer.Id); await repo.SaveAsync(cart); }