public async Task AddPayment(Payment payment) { var newPayment = _mapper.Map <Model.Payment>(payment); await Task.Run(() => { _paymentRepository.AddPayment(newPayment); _paymentRepository.Save(); var order = _orderRepository.GetOrderByOrderId(payment.OrderId); order.Payments.Add(newPayment); _orderRepository.AddPayment(newPayment); _orderRepository.Save(); OrderChanged orderChanged = new OrderChanged() { OrderId = order.OrderId, StoreName = order.Store.Name, State = "Paid" }; //notificar publish Order Changed _orderChangedService.SendMessagesAsync(orderChanged); }); }
public void Save() { _orderChangedService.AddToMessageList(_context.ChangeTracker.Entries <Order>()); _context.SaveChanges(); _orderChangedService.SendMessagesAsync(); }
public async Task SendOrderChangedToServiceBus(Order order) { await Task.Run(() => { _orderChangedService.AddToMessageList(order); _orderChangedService.SendMessagesAsync(); }); }
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); }