private async Task UpdateStorage(Guid correlationId, int sagaStatus, CheckoutInfo checkoutInfo) { var updateSagaInfo = await _repository.GetByIdAsync(correlationId); updateSagaInfo.Data = checkoutInfo.ToString <CheckoutInfo>(); updateSagaInfo.SagaStatus = sagaStatus; await _repository.UpdateAsync(updateSagaInfo); }
private async Task <Tuple <SagaInfo, CheckoutInfo> > LoadFromStorage(Guid correlationId, Guid?orderId = null) { var sagaInfo = await _repository.GetByIdAsync(correlationId); CheckoutInfo internalData; if (sagaInfo != null) { internalData = sagaInfo.Data.ToObject <CheckoutInfo>(); } else { if (!orderId.HasValue) { throw new Exception("Need to have an order id for the first time."); } var order = await _restClient.GetAsync <Order>("order_service", $"/api/orders/{orderId.Value}"); internalData = new CheckoutInfo { OrderId = order.Id, CustomerId = order.CustomerId, EmployeeId = order.EmployeeId, OrderDate = order.OrderDate, OrderStatus = (int)order.OrderStatus, Products = order.OrderDetails.Select(x => new ProductInfo { ProductId = x.ProductId, Quantity = x.Quantity }).ToList() }; var saga = new SagaInfo { Id = correlationId, // correlation id Data = internalData.ToString <CheckoutInfo>() }; sagaInfo = await _repository.AddAsync(saga); } return(new Tuple <SagaInfo, CheckoutInfo>(sagaInfo, internalData)); }