public void SaveOrders(IEnumerable <Order> orders)
        {
            var controlNumber = _configuration.GetBatchControlNumber();

            _manhattanOrderRepository.SaveOrders(orders,
                                                 _configuration.GetHeaderFilePath(controlNumber),
                                                 _configuration.GetDetailFilePath(controlNumber),
                                                 _configuration.GetSpecialInstructionFilePath(controlNumber));
        }
        public void SaveOrders(IEnumerable <Order> orders,
                               string headerFileLocation,
                               string detailsFileLocation,
                               string instructionsFileLocation)
        {
            if (headerFileLocation == null)
            {
                throw new ArgumentNullException("headerFileLocation");
            }
            if (detailsFileLocation == null)
            {
                throw new ArgumentNullException("detailsFileLocation");
            }
            if (instructionsFileLocation == null)
            {
                throw new ArgumentNullException("instructionsFileLocation");
            }

            var allOrders = orders.ToList();

            if (!allOrders.Any())
            {
                return;
            }

            var warehouseNumber  = _configuration.GetWarehouseNumber();
            var companyNumber    = _configuration.GetCompanyNumber();
            var warehouseAddress = _configuration.GetWarehouseAddress();
            var shipTo           = _configuration.GetShipTo();

            var controlNumber      = _configuration.GetBatchControlNumber();
            var batchControlNumber = warehouseNumber + controlNumber.ToString("D8");

            var detailList      = new List <ManhattanPickTicketDetail>();
            var headerList      = new List <ManhattanPickTicketHeader>();
            var instructionList = new List <ManhattanPickTicketInstruction>();

            foreach (var order in allOrders)
            {
                order.BillingAddress = warehouseAddress;

                headerList.Add(new ManhattanPickTicketHeader(order, batchControlNumber, companyNumber, warehouseNumber, shipTo, _countryReader, _carrierReadRepository));
                detailList.AddRange(CombineItems(order, batchControlNumber, companyNumber, warehouseNumber));
                var instructionControlNumber = 1;
                foreach (var instruction in order.SpecialInstructions)
                {
                    instructionList.Add(new ManhattanPickTicketInstruction("VA", "VA", instruction, batchControlNumber, order.ControlNumber, instructionControlNumber));
                    instructionControlNumber++;
                }
                instructionList.AddRange(_configuration.GetPickTicketInstructions(order, batchControlNumber, instructionControlNumber));
            }

            var headerPath      = _configuration.GetHeaderFilePath(controlNumber);
            var detailPath      = _configuration.GetDetailFilePath(controlNumber);
            var instructionPath = _configuration.GetSpecialInstructionFilePath(controlNumber);

            _headerRepository.Save(headerList, headerPath);
            _detailRepository.Save(detailList, detailPath);
            _instructionRepository.Save(instructionList, instructionPath);

            _transferControlManager.SaveTransferControl(batchControlNumber,
                                                        new List <string> {
                headerPath, detailPath, instructionPath
            },
                                                        _configuration.GetJobId());
        }