public async Task HandleAsync(SubscribeToTheNewsletter command, CancellationToken cancellationToken = default) { var subscriber = Subscriber.Subscribe(command.Id, command.Email); var discount = _discountCodeGenerator.GenerateCodeForSubscriber(_identityProvider.Next(), subscriber.Id); await _newsletterRepository.Add(subscriber, cancellationToken); await _discountRepository.Add(discount, cancellationToken); await _emailService.SendEmailWithDiscountCode(discount.GetCode(), cancellationToken); }
public async Task <IActionResult> SubscribeToNewsletter([FromBody] SubscribeToTheNewsletterDto subscribeToTheNewsletter) { var newsletterId = _identityProvider.Next(); await _commandBus.SendAsync(new SubscribeToTheNewsletter { Email = subscribeToTheNewsletter.Email, Id = newsletterId }); return(CreatedAtAction(nameof(GetSubscription), "subscriptions", new { id = newsletterId }, null )); }
public async Task <IActionResult> PlaceOrder([FromBody] PlaceOrderDto placeOrder) { var orderId = _identityProvider.Next(); await _commandBus.SendAsync(new PlaceOrder { Id = orderId, Value = placeOrder.Value, DiscountCode = placeOrder.DiscountCode }); return(CreatedAtAction(nameof(GetOrder), "orders", new { id = orderId }, null )); }