コード例 #1
0
 public async Task SendOrderChangedToServiceBus(Order order)
 {
     await Task.Run(() =>
     {
         _orderChangedService.AddToMessageList(order);
         _orderChangedService.SendMessagesAsync();
     });
 }
コード例 #2
0
        public void Save()
        {
            _orderChangedService.AddToMessageList(_context.ChangeTracker.Entries <Order>());

            _context.SaveChanges();

            _orderChangedService.SendMessagesAsync();
        }
コード例 #3
0
        private static Task Handle(Message message, CancellationToken arg2)
        {
            var orderChangedString = Encoding.UTF8.GetString(message.Body);
            var orderChanged       = JsonConvert.DeserializeObject <OrderChangedMessage>(orderChangedString);

            if (orderChanged.State == OrderState.Paid)
            {
                OrderChangedMessage orderFinishedMessage = new OrderChangedMessage
                {
                    OrderId = new Guid(message.Label),
                    State   = (OrderState)ProductionState.Finished,
                    Value   = orderChanged.Value,
                    StoreId = orderChanged.StoreId
                };

                // TODO: atribuir como status concluído apenas se o status de produção for READY

                _orderChangedService.AddToMessageList(orderFinishedMessage);
                _orderChangedService.SendMessagesAsync();
            }

            return(Task.CompletedTask);
        }