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)
            });
        }
 protected override IChangeTracker ConfigureChangeTacker()
 {
     return(_changeTrackerFactory.CreateChangeTracker()
            .TrackAll <Warehouse>()
            .Remove <Warehouse>(i => i.Id)
            .Remove <Warehouse>(i => i.IsActive));
 }
        public AppActionResult Run(CurrentUserDto user, IEnumerable <Order> orders)
        {
            var shippingDbSet = _dataService.GetDbSet <Shipping>();

            var poolingInfo = "Эту перевозку можно отправить в Pooling";

            var shipping = new Shipping
            {
                Status               = ShippingState.ShippingCreated,
                PoolingState         = ShippingPoolingState.PoolingAvailable,
                PoolingInfo          = poolingInfo,
                Id                   = Guid.NewGuid(),
                ShippingNumber       = ShippingNumberProvider.GetNextShippingNumber(),
                ProviderId           = user.ProviderId,
                ShippingCreationDate = DateTime.UtcNow
            };

            _historyService.Save(shipping.Id, "shippingSetCreated", shipping.ShippingNumber);

            shipping.DeliveryType      = DeliveryType.Delivery;
            shipping.TarifficationType = _shippingTarifficationTypeDeterminer.GetTarifficationTypeForOrders(orders);

            shippingDbSet.Add(shipping);

            UnionOrderInShipping(orders, orders, shipping, _historyService);

            var changes       = _dataService.GetChanges <Shipping>().FirstOrDefault(x => x.Entity.Id == shipping.Id);
            var changeTracker = _changeTrackerFactory.CreateChangeTracker()
                                .TrackAll <Shipping>()
                                .Remove <Shipping>(x => x.Id);

            changeTracker.LogTrackedChanges(changes);

            return(new AppActionResult
            {
                IsError = false,
                Message = "shippingSetCreated".Translate(user.Language, shipping.ShippingNumber)
            });
        }
Exemple #4
0
        public AppActionResult Run(CurrentUserDto user, IEnumerable <Order> orders)
        {
            var shippingDbSet = _dataService.GetDbSet <Shipping>();

            var shipping = new Shipping
            {
                Status               = ShippingState.ShippingCreated,
                PoolingState         = ShippingPoolingState.PoolingAvailable,
                Id                   = Guid.NewGuid(),
                ShippingNumber       = ShippingNumberProvider.GetNextShippingNumber(),
                ProviderId           = orders.FirstOrDefault()?.ProviderId ?? user.ProviderId,
                ShippingCreationDate = DateTime.UtcNow,
                UserCreatorId        = user.Id.Value
            };

            _historyService.Save(shipping.Id, "shippingSetCreated", shipping.ShippingNumber);

            shipping.DeliveryType = DeliveryType.Delivery;

            shippingDbSet.Add(shipping);

            UnionOrderInShipping(orders, orders, shipping, _historyService);

            var changes       = _dataService.GetChanges <Shipping>().FirstOrDefault(x => x.Entity.Id == shipping.Id);
            var changeTracker = _changeTrackerFactory.CreateChangeTracker()
                                .TrackAll <Shipping>()
                                .Remove <Shipping>(x => x.Id);

            changeTracker.LogTrackedChanges(changes);

            UpdateShippingFromIntegrations(shipping);
            return(new AppActionResult
            {
                IsError = false,
                Message = "shippingSetCreated".Translate(user.Language, shipping.ShippingNumber)
            });
        }
Exemple #5
0
        public AppActionResult Run(CurrentUserDto user, IEnumerable <Order> orders)
        {
            var shippingId = orders.FirstOrDefault(x => x.Status == OrderState.InShipping)?.ShippingId;

            orders = orders.Where(x => x.Status == OrderState.Created).ToList();

            var shippingDbSet = _dataService.GetDbSet <Shipping>();
            var shipping      = shippingDbSet.GetById(shippingId.Value);

            if (shipping.Status == ShippingState.ShippingConfirmed)
            {
                shipping.Status = ShippingState.ShippingRequestSent;

                string orderNumbers = string.Join(", ", orders.Select(x => x.OrderNumber));
                _historyService.Save(shipping.Id, "shippingAddOrdersResendRequest", shipping.ShippingNumber, orderNumbers);
            }

            var allOrders = _dataService.GetDbSet <Order>().Where(x => x.ShippingId == shipping.Id).ToList();

            allOrders.AddRange(orders);

            UnionOrderInShipping(allOrders, orders, shipping, _historyService);

            var changes       = _dataService.GetChanges <Shipping>().FirstOrDefault(x => x.Entity.Id == shipping.Id);
            var changeTracker = _changeTrackerFactory.CreateChangeTracker().TrackAll <Shipping>();

            changeTracker.LogTrackedChanges(changes);

            var vehicleTypes = _dataService.GetDbSet <VehicleType>();

            foreach (var orderForAddInShipping in orders)
            {
                if (orderForAddInShipping.VehicleTypeId != shipping.VehicleTypeId)
                {
                    VehicleType oldVehicleType = null;
                    VehicleType newVehicleType = null;

                    if (shipping.VehicleTypeId.HasValue)
                    {
                        oldVehicleType = vehicleTypes.GetById(shipping.VehicleTypeId.Value);
                    }

                    if (orderForAddInShipping.VehicleTypeId.HasValue)
                    {
                        newVehicleType = vehicleTypes.GetById(orderForAddInShipping.VehicleTypeId.Value);
                    }

                    _historyService.Save(shipping.Id, "fieldChangedBy",
                                         nameof(shipping.VehicleTypeId).ToLowerFirstLetter(),
                                         oldVehicleType, newVehicleType, "unionOrdersInExisted");

                    orderForAddInShipping.VehicleTypeId = shipping.VehicleTypeId;
                }

                if (orderForAddInShipping.TarifficationType != shipping.TarifficationType)
                {
                    _historyService.Save(orderForAddInShipping.Id, "fieldChangedBy",
                                         nameof(orderForAddInShipping.TarifficationType).ToLowerFirstLetter(),
                                         orderForAddInShipping.TarifficationType, shipping.TarifficationType, "unionOrdersInExisted");

                    orderForAddInShipping.TarifficationType = shipping.TarifficationType;
                }
            }

            _calcService.UpdateDeliveryCost(shipping);

            return(new AppActionResult
            {
                IsError = false,
                Message = "shippingSetCreated".Translate(user.Language, shipping.ShippingNumber)
            });
        }
Exemple #6
0
 protected override IChangeTracker ConfigureChangeTacker()
 {
     return(_changeTrackerFactory.CreateChangeTracker().TrackAll <ShippingWarehouse>());
 }
Exemple #7
0
 protected override IChangeTracker ConfigureChangeTacker()
 {
     return(_changeTrackerFactory.CreateChangeTracker()
            .TrackAll <Article>()
            .Remove <Article>(i => i.Id));
 }