Ejemplo n.º 1
0
        public IResult <string> CreatePackSchedule(ICreatePackScheduleParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var parametersResult = parameters.ToParsedParameters();

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

            var result = new CreatePackScheduleCommand(_productionUnitOfWork).Execute(_timeStamper.CurrentTimeStamp, parametersResult.ResultingObject);

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

            _productionUnitOfWork.Commit();

            var packScheduleKey = result.ResultingObject.ToPackScheduleKey();

            return(SyncParameters.Using(new SuccessResult <string>(packScheduleKey), new SyncCreatePackScheduleParameters
            {
                PackScheduleKey = packScheduleKey,
                UseSuppliedPSNum = parametersResult.ResultingObject.Parameters.PSNum != null
            }));
        }
Ejemplo n.º 2
0
 public IResult <string> CreatePackSchedule(ICreatePackScheduleParameters parameters)
 {
     try
     {
         var result = _productionServiceProvider.CreatePackSchedule(parameters);
         return(result);
     }
     catch (Exception ex)
     {
         _exceptionLogger.LogException(ex);
         return(new FailureResult <string>(null, ex.GetInnermostException().Message));
     }
 }
 internal static void AssertAsExpected(this ICreatePackScheduleParameters parameters, PackSchedule packSchedule)
 {
     Assert.AreEqual(parameters.UserToken, packSchedule.Employee.UserName);
     Assert.AreEqual(parameters.WorkTypeKey, new WorkTypeKey(packSchedule).KeyValue);
     Assert.AreEqual(parameters.ChileProductKey, new ChileProductKey(packSchedule).KeyValue);
     Assert.AreEqual(parameters.PackagingProductKey, new PackagingProductKey(packSchedule).KeyValue);
     Assert.AreEqual(parameters.ProductionLineKey, new LocationKey(packSchedule).KeyValue);
     Assert.AreEqual(parameters.ScheduledProductionDate, packSchedule.ScheduledProductionDate);
     Assert.AreEqual(parameters.ProductionDeadline, packSchedule.ProductionDeadline);
     Assert.AreEqual(parameters.SummaryOfWork, packSchedule.SummaryOfWork);
     if (parameters.CustomerKey == null)
     {
         Assert.IsNull(packSchedule.CustomerId);
         Assert.IsNull(packSchedule.Customer);
     }
     else
     {
         Assert.AreEqual(parameters.CustomerKey, new CustomerKey(packSchedule).KeyValue);
     }
     Assert.AreEqual(parameters.OrderNumber, packSchedule.OrderNumber);
     parameters.AssertAsExpected(packSchedule.DefaultBatchTargetParameters);
 }
        internal static IResult <CreatePackScheduleCommandParameters> ToParsedParameters(this ICreatePackScheduleParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var workTypeKey = KeyParserHelper.ParseResult <IWorkTypeKey>(parameters.WorkTypeKey);

            if (!workTypeKey.Success)
            {
                return(workTypeKey.ConvertTo((CreatePackScheduleCommandParameters)null));
            }

            var chileProductKey = KeyParserHelper.ParseResult <IChileProductKey>(parameters.ChileProductKey);

            if (!chileProductKey.Success)
            {
                return(chileProductKey.ConvertTo((CreatePackScheduleCommandParameters)null));
            }

            var packagingProductKey = KeyParserHelper.ParseResult <IPackagingProductKey>(parameters.PackagingProductKey);

            if (!packagingProductKey.Success)
            {
                return(packagingProductKey.ConvertTo((CreatePackScheduleCommandParameters)null));
            }

            var productionLocationKey = KeyParserHelper.ParseResult <ILocationKey>(parameters.ProductionLineKey);

            if (!productionLocationKey.Success)
            {
                return(productionLocationKey.ConvertTo((CreatePackScheduleCommandParameters)null));
            }

            CustomerKey customerKey = null;

            if (!string.IsNullOrWhiteSpace(parameters.CustomerKey))
            {
                var customerKeyResult = KeyParserHelper.ParseResult <ICustomerKey>(parameters.CustomerKey);
                if (!customerKeyResult.Success)
                {
                    return(productionLocationKey.ConvertTo((CreatePackScheduleCommandParameters)null));
                }
                customerKey = new CustomerKey(customerKeyResult.ResultingObject);
            }

            return(new SuccessResult <CreatePackScheduleCommandParameters>(new CreatePackScheduleCommandParameters
            {
                Parameters = parameters,

                WorkTypeKey = new WorkTypeKey(workTypeKey.ResultingObject),
                ChileProductKey = new ChileProductKey(chileProductKey.ResultingObject),
                PackagingProductKey = new PackagingProductKey(packagingProductKey.ResultingObject),
                ProductionLocationKey = new LocationKey(productionLocationKey.ResultingObject),
                CustomerKey = customerKey
            }));
        }