public IResult <string> CreateWarehouseOrder(ISetOrderParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var parsedParameters = new SetInventoryShipmentOrderConductorParameters <ISetOrderParameters>(parameters);

            if (!parsedParameters.Result.Success)
            {
                return(parsedParameters.Result.ConvertTo <string>());
            }

            var createResult = new CreateInterWarehouseOrderConductor(_inventoryShipmentOrderUnitOfWork).Create(_timeStamper.CurrentTimeStamp, parsedParameters);

            if (!createResult.Success)
            {
                return(createResult.ConvertTo <string>());
            }

            _inventoryShipmentOrderUnitOfWork.Commit();

            var key = createResult.ResultingObject.ToInventoryShipmentOrderKey();

            return(SyncParameters.Using(new SuccessResult <string>(key), new SyncInventoryShipmentOrderParameters
            {
                InventoryShipmentOrderKey = key,
                New = true
            }));
        }
Ejemplo n.º 2
0
        protected IResult <InventoryShipmentOrder> SetOrder <TParams>(InventoryShipmentOrder inventoryShipmentOrder, DateTime timeStamp, SetInventoryShipmentOrderConductorParameters <TParams> parameters)
            where TParams : ISetOrderParameters
        {
            if (inventoryShipmentOrder == null)
            {
                throw new ArgumentNullException("inventoryShipmentOrder");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var employeeResult = new GetEmployeeCommand(UnitOfWork).GetEmployee(parameters.Params);

            if (!employeeResult.Success)
            {
                return(employeeResult.ConvertTo <InventoryShipmentOrder>());
            }

            inventoryShipmentOrder.EmployeeId = employeeResult.ResultingObject.EmployeeId;
            inventoryShipmentOrder.TimeStamp  = timeStamp;

            if (parameters.Params.HeaderParameters != null)
            {
                inventoryShipmentOrder.SetHeaderParameters(parameters.Params.HeaderParameters);
            }

            if (parameters.DestinationFacilityKey != null)
            {
                var destinationFacility = UnitOfWork.FacilityRepository.FindByKey(parameters.DestinationFacilityKey, f => f.Locations);
                if (destinationFacility == null)
                {
                    return(new InvalidResult <InventoryShipmentOrder>(null, string.Format(UserMessages.FacilityNotFound, parameters.DestinationFacilityKey)));
                }

                var validateFacility = ValidateDestinationFacility(destinationFacility);
                if (!validateFacility.Success)
                {
                    return(validateFacility.ConvertTo <InventoryShipmentOrder>());
                }

                inventoryShipmentOrder.DestinationFacility   = destinationFacility;
                inventoryShipmentOrder.DestinationFacilityId = destinationFacility.Id;
            }

            if (parameters.SourceFacilityKey != null)
            {
                var sourceFacility = UnitOfWork.FacilityRepository.FindByKey(parameters.SourceFacilityKey, f => f.Locations);
                if (sourceFacility == null)
                {
                    return(new InvalidResult <InventoryShipmentOrder>(null, string.Format(UserMessages.FacilityNotFound, parameters.SourceFacilityKey)));
                }

                var currentKeys = inventoryShipmentOrder.PickedInventory.Items.Select(i => new LocationKey(i.FromLocation)).ToList();
                if (currentKeys.Any(l => sourceFacility.Locations.All(c => !l.Equals(c))))
                {
                    return(new InvalidResult <InventoryShipmentOrder>(null, string.Format(UserMessages.SourceLocationMustBelongToFacility, parameters.SourceFacilityKey)));
                }

                inventoryShipmentOrder.SourceFacility   = sourceFacility;
                inventoryShipmentOrder.SourceFacilityId = sourceFacility.Id;
            }

            if (parameters.Params.SetShipmentInformation != null)
            {
                inventoryShipmentOrder.ShipmentInformation.SetShipmentInformation(parameters.Params.SetShipmentInformation);
            }

            if (parameters.Params.InventoryPickOrderItems != null)
            {
                var pickOrderResult = new InventoryPickOrderCommand(UnitOfWork).Execute(inventoryShipmentOrder.InventoryPickOrder, parameters.PickOrderItems);
                if (!pickOrderResult.Success)
                {
                    return(pickOrderResult.ConvertTo <InventoryShipmentOrder>());
                }
            }

            return(new SuccessResult <InventoryShipmentOrder>(inventoryShipmentOrder));
        }
        internal IResult <InventoryShipmentOrder> Create <TParams>(DateTime timestamp, SetInventoryShipmentOrderConductorParameters <TParams> parameters)
            where TParams : ISetOrderParameters
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var employeeResult = new GetEmployeeCommand(_interWarehouseOrderUnitOfWork).GetEmployee(parameters.Params);

            if (!employeeResult.Success)
            {
                return(employeeResult.ConvertTo <InventoryShipmentOrder>());
            }

            var pickedInventoryResult = new CreatePickedInventoryCommand(_interWarehouseOrderUnitOfWork).Execute(new CreatePickedInventoryCommandParameters
            {
                EmployeeKey  = new EmployeeKey(employeeResult.ResultingObject),
                TimeStamp    = timestamp,
                PickedReason = PickedReason.InterWarehouseMovement
            });

            if (!pickedInventoryResult.Success)
            {
                return(pickedInventoryResult.ConvertTo <InventoryShipmentOrder>());
            }

            var pickedOrderResult = new CreateInventoryPickOrderCommand(_interWarehouseOrderUnitOfWork).Execute(pickedInventoryResult.ResultingObject);

            if (!pickedOrderResult.Success)
            {
                return(pickedOrderResult.ConvertTo <InventoryShipmentOrder>());
            }

            var shipmentInfoResult = new CreateShipmentInformationCommand(_interWarehouseOrderUnitOfWork).Execute(timestamp, parameters.Params.SetShipmentInformation);

            if (!shipmentInfoResult.Success)
            {
                return(shipmentInfoResult.ConvertTo <InventoryShipmentOrder>());
            }

            var order = new InventoryShipmentOrder
            {
                OrderType               = InventoryShipmentOrderTypeEnum.InterWarehouseOrder,
                OrderStatus             = OrderStatus.Scheduled,
                DateCreated             = pickedInventoryResult.ResultingObject.DateCreated,
                Sequence                = pickedInventoryResult.ResultingObject.Sequence,
                PickedInventory         = pickedInventoryResult.ResultingObject,
                InventoryPickOrder      = pickedOrderResult.ResultingObject,
                ShipmentInformation     = shipmentInfoResult.ResultingObject,
                ShipmentInfoDateCreated = shipmentInfoResult.ResultingObject.DateCreated,
                ShipmentInfoSequence    = shipmentInfoResult.ResultingObject.Sequence,
                MoveNum = new GetMoveNum(_interWarehouseOrderUnitOfWork.InventoryShipmentOrderRepository).Get(pickedInventoryResult.ResultingObject.DateCreated.Year)
            };

            if (parameters.Params.HeaderParameters != null)
            {
                order.SetHeaderParameters(parameters.Params.HeaderParameters);
            }

            order = _interWarehouseOrderUnitOfWork.InventoryShipmentOrderRepository.Add(order);

            return(new UpdateInterWarehouseOrderConductor(_interWarehouseOrderUnitOfWork).Update(order, timestamp, parameters));
        }
 internal IResult <InventoryShipmentOrder> Update <TParams>(InventoryShipmentOrder inventoryShipmentOrder, DateTime timeStamp, SetInventoryShipmentOrderConductorParameters <TParams> parameters)
     where TParams : ISetOrderParameters
 {
     return(SetOrder(inventoryShipmentOrder, timeStamp, parameters));
 }