public IResult <string> CreateCustomerContract(ICreateCustomerContractParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var parsedParametersResult = parameters.ToParsedParameters(); if (!parsedParametersResult.Success) { return(parsedParametersResult.ConvertTo <string>()); } var commandResult = new CreateCustomerContractConductor(_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 = true })); }
public IResult <string> CreateCustomerContract(ICreateCustomerContractParameters parameters) { try { return(_salesServiceProvider.CreateCustomerContract(parameters)); } catch (Exception ex) { ex = ex.GetBaseException(); _exceptionLogger.LogException(ex); return(new FailureResult <string>(null, ex.Message)); } }
internal static IResult <CreateCustomerContractCommandParameters> ToParsedParameters(this ICreateCustomerContractParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } if (parameters.ContractItems == null || !parameters.ContractItems.Any()) { return(new InvalidResult <CreateCustomerContractCommandParameters>(null, UserMessages.ContractItemsRequired)); } if (parameters.TermBegin != null && parameters.TermEnd != null && parameters.TermBegin >= parameters.TermEnd) { return(new InvalidResult <CreateCustomerContractCommandParameters>(null, string.Format(UserMessages.ContractTermMustBeginBeforeEnd, parameters.TermBegin, parameters.TermEnd))); } var customerKeyResult = KeyParserHelper.ParseResult <ICustomerKey>(parameters.CustomerKey); if (!customerKeyResult.Success) { return(customerKeyResult.ConvertTo((CreateCustomerContractCommandParameters)null)); } FacilityKey facilityKey = null; if (!string.IsNullOrWhiteSpace(parameters.DefaultPickFromFacilityKey)) { var warehouseKeyResult = KeyParserHelper.ParseResult <IFacilityKey>(parameters.DefaultPickFromFacilityKey); if (!warehouseKeyResult.Success) { return(warehouseKeyResult.ConvertTo((CreateCustomerContractCommandParameters)null)); } facilityKey = new FacilityKey(warehouseKeyResult.ResultingObject); } var parsedItems = new List <SetContractItemParameters>(); foreach (var item in parameters.ContractItems) { var itemResult = item.ToParsedParameters(); if (!itemResult.Success) { return(itemResult.ConvertTo((CreateCustomerContractCommandParameters)null)); } parsedItems.Add(itemResult.ResultingObject); } return(new SuccessResult <CreateCustomerContractCommandParameters>(new CreateCustomerContractCommandParameters { CreateCustomerContractParameters = parameters, CustomerKey = new CustomerKey(customerKeyResult.ResultingObject), DefaultPickFromFacilityKey = facilityKey, ContractItems = parsedItems })); }