protected void UnionOrderInShipping(IEnumerable <Order> allOrders, IEnumerable <Order> newOrders, Shipping shipping, IHistoryService historyService) { _shippingCalculationService.RecalculateShipping(shipping, allOrders); _shippingGetRouteService.UpdateRoute(shipping, allOrders); foreach (var order in allOrders) { if (order.Status == null || order.Status == OrderState.InShipping) { order.Status = order.Status == OrderState.Created ? OrderState.InShipping : order.Status; order.ShippingStatus = VehicleState.VehicleWaiting; order.CarrierId = order.CarrierId ?? shipping.CarrierId; historyService.Save(order.Id, "orderSetInShipping", order.OrderNumber, shipping.ShippingNumber); historyService.Save(shipping.Id, "shippingAddOrder", order.OrderNumber, shipping.ShippingNumber); } order.ShippingNumber = shipping.ShippingNumber; order.OrderShippingStatus = shipping.Status; } foreach (var order in newOrders) { order.ShippingId = shipping.Id; order.Status = OrderState.InShipping; order.ShippingNumber = shipping.ShippingNumber; order.ShippingStatus = VehicleState.VehicleWaiting; order.DeliveryStatus = VehicleState.VehicleEmpty; order.CarrierId = shipping.CarrierId; historyService.Save(order.Id, "orderSetInShipping", order.OrderNumber, shipping.ShippingNumber); historyService.Save(shipping.Id, "shippingAddOrder", order.OrderNumber, shipping.ShippingNumber); } }
public AppActionResult Run(CurrentUserDto user, Order order) { order.Status = OrderState.Created; order.ShippingStatus = VehicleState.VehicleEmpty; order.DeliveryStatus = VehicleState.VehicleEmpty; var shipping = _dataService.GetById <Shipping>(order.ShippingId.Value); order.ShippingId = null; order.ShippingNumber = null; order.OrderShippingStatus = null; _historyService.Save(order.Id, "orderRemovedFromShipping", order.OrderNumber, shipping.ShippingNumber); var orders = _dataService.GetDbSet <Order>().Where(x => x.ShippingId == shipping.Id && x.Id != order.Id) .ToList(); _historyService.Save(shipping.Id, "orderRemovedFromShipping", order.OrderNumber, shipping.ShippingNumber); _shippingCalculationService.RecalculateShipping(shipping, orders); _shippingGetRouteService.UpdateRoute(shipping, orders); var changes = _dataService.GetChanges <Shipping>().FirstOrDefault(x => x.Entity.Id == shipping.Id); var changeTracker = _changeTrackerFactory.CreateChangeTracker().TrackAll <Shipping>(); changeTracker.LogTrackedChanges(changes); return(new AppActionResult { IsError = false, Message = "orderRemovedFromShipping".Translate(user.Language, order.OrderNumber, shipping.ShippingNumber) }); }