public IResult <TreatmentOrder> CreateTreatmentOrder <TParams>(DateTime timestamp, CreateTreatmentOrderConductorParameters <TParams> parameters) where TParams : ICreateTreatmentOrderParameters { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(_treatmentOrderUnitOfWork).GetEmployee(parameters.Params); if (!employeeResult.Success) { return(employeeResult.ConvertTo <TreatmentOrder>()); } var dateCreated = timestamp.Date; var pickedInventoryResult = new CreatePickedInventoryCommand(_treatmentOrderUnitOfWork).Execute(new CreatePickedInventoryCommandParameters { EmployeeKey = new EmployeeKey(employeeResult.ResultingObject), TimeStamp = dateCreated, PickedReason = PickedReason.TreatmentOrder }); if (!pickedInventoryResult.Success) { return(pickedInventoryResult.ConvertTo <TreatmentOrder>()); } var pickedOrderResult = new CreateInventoryPickOrderCommand(_treatmentOrderUnitOfWork).Execute(pickedInventoryResult.ResultingObject); if (!pickedOrderResult.Success) { return(pickedOrderResult.ConvertTo <TreatmentOrder>()); } var shipmentInfoResult = new CreateShipmentInformationCommand(_treatmentOrderUnitOfWork).Execute(dateCreated); if (!shipmentInfoResult.Success) { return(shipmentInfoResult.ConvertTo <TreatmentOrder>()); } var treatmentOrder = _treatmentOrderUnitOfWork.TreatmentOrderRepository.Add(new TreatmentOrder { DateCreated = pickedInventoryResult.ResultingObject.DateCreated, Sequence = pickedInventoryResult.ResultingObject.Sequence, InventoryTreatmentId = parameters.TreatmentKey.InventoryTreatmentKey_Id, InventoryShipmentOrder = new InventoryShipmentOrder { DateCreated = pickedInventoryResult.ResultingObject.DateCreated, Sequence = pickedInventoryResult.ResultingObject.Sequence, OrderType = InventoryShipmentOrderTypeEnum.TreatmentOrder, OrderStatus = OrderStatus.Scheduled, ShipmentInfoDateCreated = shipmentInfoResult.ResultingObject.DateCreated, ShipmentInfoSequence = shipmentInfoResult.ResultingObject.Sequence, ShipmentInformation = shipmentInfoResult.ResultingObject, InventoryPickOrder = pickedOrderResult.ResultingObject, PickedInventory = pickedInventoryResult.ResultingObject, MoveNum = new GetMoveNum(_treatmentOrderUnitOfWork.InventoryShipmentOrderRepository).Get(pickedInventoryResult.ResultingObject.DateCreated.Year) } }); return(new UpdateTreatmentOrderConductor(_treatmentOrderUnitOfWork).Update(treatmentOrder, timestamp, parameters)); }
internal IResult <SalesOrder> Execute(DateTime timestamp, CreateSalesOrderConductorParameters parameters) { if (timestamp == null) { throw new ArgumentNullException("timestamp"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(SalesUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <SalesOrder>()); } Customer customer = null; if (parameters.CustomerKey != null) { customer = SalesUnitOfWork.CustomerRepository.FindByKey(parameters.CustomerKey, c => c.Company.Contacts, c => c.Contracts.Select(r => r.ContractItems)); } if (customer == null && !parameters.CreateParameters.IsMiscellaneous) { return(new InvalidResult <SalesOrder>(null, string.Format(UserMessages.CustomerNotFound, parameters.CustomerKey))); } var pickedInventoryResult = new CreatePickedInventoryCommand(SalesUnitOfWork).Execute(new CreatePickedInventoryCommandParameters { EmployeeKey = employeeResult.ResultingObject.ToEmployeeKey(), PickedReason = PickedReason.SalesOrder, TimeStamp = timestamp }); if (!pickedInventoryResult.Success) { pickedInventoryResult.ConvertTo <SalesOrder>(); } var pickedInventory = pickedInventoryResult.ResultingObject; pickedInventory.Items = null; var pickOrderResult = new CreateInventoryPickOrderCommand(SalesUnitOfWork).Execute(pickedInventory); if (!pickOrderResult.Success) { return(pickOrderResult.ConvertTo <SalesOrder>()); } var pickOrder = pickOrderResult.ResultingObject; pickOrder.Items = null; var shipmentInformationResult = new CreateShipmentInformationCommand(SalesUnitOfWork).Execute(timestamp.Date); if (!shipmentInformationResult.Success) { return(shipmentInformationResult.ConvertTo <SalesOrder>()); } var shipmentInfo = shipmentInformationResult.ResultingObject; var salesOrder = new SalesOrder { DateCreated = pickedInventory.DateCreated, Sequence = pickedInventory.Sequence, CustomerId = customer == null ? (int?)null : customer.Id, BrokerId = customer == null ? (int?)null : customer.BrokerId, InventoryShipmentOrder = new InventoryShipmentOrder { DateCreated = pickedInventory.DateCreated, Sequence = pickedInventory.Sequence, EmployeeId = employeeResult.ResultingObject.EmployeeId, TimeStamp = timestamp, OrderType = parameters.CreateParameters.IsMiscellaneous ? InventoryShipmentOrderTypeEnum.MiscellaneousOrder : InventoryShipmentOrderTypeEnum.SalesOrder, ShipmentInfoDateCreated = shipmentInfo.DateCreated, ShipmentInfoSequence = shipmentInfo.Sequence, ShipmentInformation = shipmentInfo, MoveNum = SalesUnitOfWork.SalesOrderRepository.SourceQuery.Select(s => s.InventoryShipmentOrder.MoveNum).Where(n => n != null).DefaultIfEmpty(0).Max() + 1 }, Customer = customer, OrderStatus = SalesOrderStatus.Ordered }; var setResult = SetSalesOrder(salesOrder, timestamp, parameters); if (!setResult.Success) { return(setResult); } salesOrder = SalesUnitOfWork.SalesOrderRepository.Add(salesOrder); return(new SuccessResult <SalesOrder>(salesOrder)); }
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)); }