public async Task <bool> Handle(ChangeStatusOrderAlterationCommend request, CancellationToken cancellationToken) { if (request == null) { throw new NullReferenceException("CangeOrderStatusCommand is null!"); } var orderAlter = await _orderAlterationRepository.SingleOrDefaultAsync(x => x.Id == request.Id); if (orderAlter == null) { return(false); } orderAlter.SetOrderStatus(request.OrderStatus); try { _orderAlterationRepository.UpdateUoW(orderAlter); ////Save Local Integration Event with pending status (InsertOrderPaidEvent Or InsertAlterationFinishedEvent) //var orderPaidEvent = await InsertOrderPaidEvent(orderAlter); //var alterationFinishedEvent = await InsertAlterationFinishedEvent(orderAlter); await _orderAlterationRepository.SaveChangesAsync(); try { // publish Integration event if (orderAlter.OrderStatusId == Status.Paid.Id) { var orderPaidEvent = new OrderPaidEvent(orderAlter.Id); await _endpoint.Publish(orderPaidEvent); } else if (orderAlter.OrderStatusId == Status.Done.Id) { var alterationFinishedEvent = new AlterationFinishedEvent(orderAlter.Id); await _endpoint.Publish(alterationFinishedEvent); } } catch (Exception ex) { //update Local Integration Event to ready status //await _localIntegrationEventRepository.UpdateLocalIntegrationEvent(orderPaidEvent.Id); } } catch (Exception ex) { throw; } return(true); }
private async Task ProccessEvents() { List <LocalIntegrationEvent> localIntegrationEvents = await _backgroundTaskLocalIntegrationEventService.GetAllReadyToPulishAndUpdateTheirStatuses(); foreach (var @event in localIntegrationEvents) { object obj = @event.JsonBoby.DeserializeJson(); var messageId = @event.UniqueId; messageId = await _endpoint.Publish(obj, messageId).ConfigureAwait(false); @event.UniqueId = messageId; @event.Status = (int)EnumLocalIntegrationEventStatus.Published; await _backgroundTaskLocalIntegrationEventService.UpdateAsync(@event); } }