示例#1
0
 public IResult <string> CreateIntraWarehouseOrder(ICreateIntraWarehouseOrderParameters parameters)
 {
     try
     {
         return(_intraWarehouseOrderServiceProvider.CreateIntraWarehouseOrder(parameters));
     }
     catch (Exception ex)
     {
         _exceptionLogger.LogException(ex);
         return(new FailureResult <string>(null, ex.Message));
     }
 }
        public IResult <string> CreateIntraWarehouseOrder(ICreateIntraWarehouseOrderParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var createResult = new IntraWarehouseOrderConductor(_intraWarehouseOrderUnitOfWork).Create(_timeStamper.CurrentTimeStamp, parameters);

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

            _intraWarehouseOrderUnitOfWork.Commit();

            var key = createResult.ResultingObject.ToIntraWarehouseOrderKey();

            return(SyncParameters.Using(new SuccessResult <string>(key), key));
        }
        internal IResult <IntraWarehouseOrder> Create(DateTime timestamp, ICreateIntraWarehouseOrderParameters parameters)
        {
            var orderResult = GetUpdatedOrder(timestamp, null, parameters);

            if (!orderResult.Success)
            {
                return(orderResult);
            }
            var order = orderResult.ResultingObject;

            order.TrackingSheetNumber = parameters.TrackingSheetNumber;

            if (parameters.PickedItems == null || !parameters.PickedItems.Any())
            {
                return(new InvalidResult <IntraWarehouseOrder>(null, UserMessages.PickedItemsManifestRequired));
            }

            var items = parameters.PickedItems.ToParsedParameters();

            if (!items.Success)
            {
                return(items.ConvertTo <IntraWarehouseOrder>());
            }

            var locationKey = items.ResultingObject.Select(i => new LocationKey(i.InventoryKey)).First();
            var location    = UnitOfWork.LocationRepository.FindByKey(locationKey, l => l.Facility.Locations);

            if (location == null)
            {
                return(new InvalidResult <IntraWarehouseOrder>(null, string.Format(UserMessages.LocationNotFound, locationKey)));
            }

            var locationKeys = location.Facility.Locations.Select(l => new LocationKey(l)).ToList();

            if (items.ResultingObject.Any(i => locationKeys.All(k => !k.Equals(i.InventoryKey)) || locationKeys.All(k => !k.Equals(i.CurrentLocationKey))))
            {
                return(new InvalidResult <IntraWarehouseOrder>(null, UserMessages.IntraWarehouseOrderDifferentWarehouses));
            }

            var pickedResult = UpdatePickedInventory(null, order.Employee, order.TimeStamp, order.PickedInventory, items.ResultingObject, true);

            if (!pickedResult.Success)
            {
                return(pickedResult.ConvertTo <IntraWarehouseOrder>());
            }

            var transactionParameters    = new InventoryTransactionParameters(order, order.TimeStamp, InventoryTransactionType.InternalMovement, order.TrackingSheetNumber.ToString());
            var createTransactionCommand = new CreateInventoryTransactionCommand(UnitOfWork);

            foreach (var item in items.ResultingObject)
            {
                var result = createTransactionCommand.Create(transactionParameters, item.InventoryKey, -item.Quantity);
                if (!result.Success)
                {
                    return(result.ConvertTo <IntraWarehouseOrder>());
                }

                result = createTransactionCommand.Create(transactionParameters, new InventoryKey(item.InventoryKey, item.InventoryKey, item.CurrentLocationKey, item.InventoryKey, item.InventoryKey.InventoryKey_ToteKey), item.Quantity);
                if (!result.Success)
                {
                    return(result.ConvertTo <IntraWarehouseOrder>());
                }
            }

            return(new SuccessResult <IntraWarehouseOrder>(order));
        }