Ejemplo n.º 1
0
        private void FillOrder(CsvLineData orderData, Order order)
        {
            var cons = new Consignment {
                ConsigneeName = orderData.ConsigneeName, Number = orderData.ConsignmentNumber, OrderNumber = orderData.OrderNumber
            };
            var parcel = new Parcel {
                Code = orderData.ParcelCode, ConsignmentNumber = orderData.ConsignmentNumber
            };
            var item = new Item {
                Currency = orderData.ItemCurrency, Description = orderData.ItemDescription, ParcelCode = orderData.ParcelCode, Quantity = orderData.ItemQuantity, Value = orderData.ItemValue, Weight = orderData.ItemWeight
            };

            parcel.Items.Add(item);
            cons.Parcels.Add(parcel);
            order.Consignments.Add(cons);
        }
Ejemplo n.º 2
0
        private List <CsvLineData> GetDataList(IEnumerable <string> orders, string[] headers)
        {
            var ordersList = new List <CsvLineData>();

            foreach (var order in orders)
            {
                var dataArray = order.Split(new string[] { "," }, StringSplitOptions.None);
                dataArray = dataArray.Select(x => x.Trim()).ToArray();

                var dataLine = new CsvLineData();

                for (var i = 0; i < dataArray.Length; i++)
                {
                    var mappingKey = DataHelper.HeaderMapping.FirstOrDefault(h => h.Value == headers[i]).Key;

                    switch (mappingKey)
                    {
                    case nameof(dataLine.OrderNumber):
                        dataLine.OrderNumber = dataArray[i];
                        break;

                    case nameof(dataLine.ConsignmentNumber):
                        dataLine.ConsignmentNumber = dataArray[i];
                        break;

                    case nameof(dataLine.ConsigneeName):
                        dataLine.ConsigneeName = dataArray[i];
                        break;

                    case nameof(dataLine.ParcelCode):
                        dataLine.ParcelCode = dataArray[i];
                        break;

                    case nameof(dataLine.ItemValue):
                        if (!string.IsNullOrEmpty(dataArray[i]))
                        {
                            if (double.TryParse(dataArray[i], out double v))
                            {
                                dataLine.ItemValue = v;
                            }
                        }
                        break;

                    case nameof(dataLine.ItemQuantity):
                        if (!string.IsNullOrEmpty(dataArray[i]))
                        {
                            if (int.TryParse(dataArray[i], out int v))
                            {
                                dataLine.ItemQuantity = v;
                            }
                        }
                        break;

                    case nameof(dataLine.ItemDescription):
                        dataLine.ItemDescription = dataArray[i];
                        break;

                    case nameof(dataLine.ItemCurrency):
                        dataLine.ItemCurrency = dataArray[i];
                        break;

                    case nameof(dataLine.ItemWeight):
                        if (!string.IsNullOrEmpty(dataArray[i]))
                        {
                            if (double.TryParse(dataArray[i], out double v))
                            {
                                dataLine.ItemWeight = v;
                            }
                        }
                        break;

                    case nameof(dataLine.Address1):
                        dataLine.Address1 = dataArray[i];
                        break;

                    case nameof(dataLine.Address2):
                        dataLine.Address2 = dataArray[i];
                        break;

                    case nameof(dataLine.City):
                        dataLine.City = dataArray[i];
                        break;

                    case nameof(dataLine.State):
                        dataLine.State = dataArray[i];
                        break;

                    case nameof(dataLine.CountryCode):
                        dataLine.CountryCode = dataArray[i];
                        break;
                    }
                }

                ordersList.Add(dataLine);
            }
            return(ordersList);
        }