Beispiel #1
0
        public async Task SendEmailNotification(Order order)
        {
            var queue = await GetQueue();

            var orderReceivedMessage = new OrderReceivedMessage {
                OrderId = order.Id, Amount = order.Amount
            };

            var queueMessage = new CloudQueueMessage(JsonConvert.SerializeObject(orderReceivedMessage));

            try
            {
                _logger.LogInformation("Sending email request to MailerService");

                await queue.AddMessageAsync(queueMessage);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Couldn't send email request, saving to outbox for later retry");

                // save to outbox so we can try sending later!

                _db.Outbox.Add(new PendingOrderNotification {
                    OrderId = order.Id
                });

                await _db.SaveChangesAsync();
            }
        }
Beispiel #2
0
        public Task <bool> SendEmail(OrderReceivedMessage orderMessage)
        {
            var random = new Random();
            var x      = random.Next(10);

            if (x > 6)
            {
                return(Task.FromResult(false));
            }
            else
            {
                return(Task.FromResult(true));
            }
        }