public ActionResult OrderAnalysis(long shopifyOrderId) { var financialSummary = _analysisDataService.GetOrderFinancialSummary(shopifyOrderId); var rootAction = _pendingActionService.Create(shopifyOrderId); var record = _shopifyOrderRepository.RetrieveOrder(shopifyOrderId); var order = _shopifyJsonService.RetrieveOrder(record.ShopifyOrderId); var finAnalyzer = record.ToFinAnalyzer(order); var shopifyDetail = new { ShopifyOrderId = shopifyOrderId, ShopifyOrderNbr = record.ShopifyOrderNumber, ShopifyOrderHref = _shopifyUrlService.ShopifyOrderUrl(shopifyOrderId), ShopifyCustomerId = record.ShopifyCustomer.ShopifyCustomerId, ShopifyCustomerHref = _shopifyUrlService.ShopifyCustomerUrl(record.ShopifyCustomer.ShopifyCustomerId), ShopifyFinancialStatus = record.ShopifyFinancialStatus, ShopifyFulfillmentStatus = record.ShopifyFulfillmentStatus, ShopifyIsCancelled = record.ShopifyIsCancelled, ShopifyAreAllItemsRefunded = record.IsCancelledOrAllRefunded(), Transfer = finAnalyzer, }; return(new JsonNetResult(new { FinancialSummary = financialSummary, ShopifyDetail = shopifyDetail, RootAction = rootAction, })); }
private void UpsertOrderAndCustomer(Order order) { var monsterCustomerRecord = _shopifyCustomerPull.UpsertCustomer(order.customer); using (var transaction = _orderRepository.BeginTransaction()) { var existingOrder = _orderRepository.RetrieveOrder(order.id); if (existingOrder == null) { var newOrder = new ShopifyOrder(); newOrder.ShopifyOrderId = order.id; newOrder.ShopifyOrderNumber = order.name; newOrder.ShopifyTotalPrice = order.total_price; newOrder.ShopifyFinancialStatus = order.financial_status; newOrder.ShopifyFulfillmentStatus = order.fulfillment_status; newOrder.ShopifyIsCancelled = order.IsCancelled; newOrder.ShopifyAreAllItemsRefunded = order.AreAllLineItemsRefunded; newOrder.ShopifyTotalQuantity = order.NetOrderedQuantity; newOrder.NeedsOrderPut = false; newOrder.NeedsTransactionGet = true; newOrder.ErrorCount = 0; newOrder.Ignore = false; newOrder.CustomerMonsterId = monsterCustomerRecord.MonsterId; newOrder.DateCreated = DateTime.UtcNow; newOrder.LastUpdated = DateTime.UtcNow; _executionLogService.Log(LogBuilder.DetectedNewShopifyOrder(newOrder)); _orderRepository.InsertOrder(newOrder); } else { existingOrder.ShopifyTotalPrice = order.total_price; existingOrder.ShopifyFinancialStatus = order.financial_status; existingOrder.ShopifyFulfillmentStatus = order.fulfillment_status; existingOrder.ShopifyIsCancelled = order.IsCancelled; existingOrder.ShopifyAreAllItemsRefunded = order.AreAllLineItemsRefunded; existingOrder.ShopifyTotalQuantity = order.NetOrderedQuantity; if (existingOrder.StatusChangeDetected(order)) { existingOrder.NeedsOrderPut = true; } existingOrder.NeedsTransactionGet = true; existingOrder.LastUpdated = DateTime.UtcNow; _executionLogService.Log(LogBuilder.DetectedUpdateShopifyOrder(existingOrder)); _orderRepository.SaveChanges(); } _shopifyJsonService.Upsert(ShopifyJsonType.Order, order.id, order.SerializeToJson()); transaction.Commit(); } }
public void RunTransactionIfPullNeeded(long shopifyOrderId) { var order = _orderRepository.RetrieveOrder(shopifyOrderId); if (order.NeedsTransactionGet) { PullTransactionsFromShopify(order); } }