Example #1
0
        public IResult <string> UpdateCustomerContract(IUpdateCustomerContractParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var parsedParametersResult = parameters.ToParsedParameters();

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

            var commandResult = new UpdateCustomerContractConductor(_inventoryShipmentOrderUnitOfWork).Execute(parsedParametersResult.ResultingObject, _timeStamper.CurrentTimeStamp);

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

            _inventoryShipmentOrderUnitOfWork.Commit();

            var contractKey = commandResult.ResultingObject.ToContractKey();

            return(SyncParameters.Using(new SuccessResult <string>(contractKey), new SyncCustomerContractParameters
            {
                ContractKey = contractKey,
                New = false
            }));
        }
Example #2
0
 public IResult UpdateCustomerContract(IUpdateCustomerContractParameters parameters)
 {
     try
     {
         return(_salesServiceProvider.UpdateCustomerContract(parameters));
     }
     catch (Exception ex)
     {
         ex = ex.GetBaseException();
         _exceptionLogger.LogException(ex);
         return(new FailureResult <string>(null, ex.Message));
     }
 }
Example #3
0
        internal static IResult <UpdateCustomerContractCommandParameters> ToParsedParameters(this IUpdateCustomerContractParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            if (parameters.ContractItems == null || !parameters.ContractItems.Any())
            {
                return(new InvalidResult <UpdateCustomerContractCommandParameters>(null, UserMessages.ContractItemsRequired));
            }

            if (parameters.TermBegin >= parameters.TermEnd)
            {
                return(new InvalidResult <UpdateCustomerContractCommandParameters>(null, string.Format(UserMessages.ContractTermMustBeginBeforeEnd, parameters.TermBegin, parameters.TermEnd)));
            }

            var contractKeyResult = KeyParserHelper.ParseResult <IContractKey>(parameters.ContractKey);

            if (!contractKeyResult.Success)
            {
                return(contractKeyResult.ConvertTo((UpdateCustomerContractCommandParameters)null));
            }

            var customerKeyResult = KeyParserHelper.ParseResult <ICustomerKey>(parameters.CustomerKey);

            if (!customerKeyResult.Success)
            {
                return(customerKeyResult.ConvertTo((UpdateCustomerContractCommandParameters)null));
            }

            var brokerKeyResult = KeyParserHelper.ParseResult <ICompanyKey>(parameters.BrokerKey);

            if (!brokerKeyResult.Success)
            {
                return(brokerKeyResult.ConvertTo((UpdateCustomerContractCommandParameters)null));
            }

            FacilityKey facilityKey = null;

            if (!string.IsNullOrWhiteSpace(parameters.DefaultPickFromWarehouseKey))
            {
                var warehouseKeyResult = KeyParserHelper.ParseResult <IFacilityKey>(parameters.DefaultPickFromWarehouseKey);
                if (!warehouseKeyResult.Success)
                {
                    return(warehouseKeyResult.ConvertTo((UpdateCustomerContractCommandParameters)null));
                }
                facilityKey = new FacilityKey(warehouseKeyResult.ResultingObject);
            }

            var contractItems = new List <SetContractItemParameters>();

            foreach (var item in parameters.ContractItems)
            {
                var parseItemResult = item.ToParsedParameters();
                if (!parseItemResult.Success)
                {
                    return(parseItemResult.ConvertTo((UpdateCustomerContractCommandParameters)null));
                }
                contractItems.Add(parseItemResult.ResultingObject);
            }

            return(new SuccessResult <UpdateCustomerContractCommandParameters>(new UpdateCustomerContractCommandParameters
            {
                UpdateCustomerContractParameters = parameters,
                ContractKey = new ContractKey(contractKeyResult.ResultingObject),
                CustomerKey = new CustomerKey(customerKeyResult.ResultingObject),
                BrokerKey = new CompanyKey(brokerKeyResult.ResultingObject),
                DefaultPickFromFacilityKey = facilityKey,

                ContractItems = contractItems
            }));
        }