public List<BulkShippingUpdateDataTransferObject> ValidateAndBulkShippingUpdateOrders(Stream rawFile, ref Dictionary<string, List<string>> parseErrors)
        {
            var bulkShippingUpdateDataTransferObjects = new List<BulkShippingUpdateDataTransferObject>();

            if (rawFile != null)
            {
                using (var file = new CsvReader(new StreamReader(rawFile), new CsvConfiguration{HasHeaderRecord = true}))
                {
                    while (file.Read())
                    {
                        var orderId = file.GetField<int?>(0);

                        //skip blank rows
                        if (!orderId.HasValue)
                            continue;
                        
                        //check for duplicates
                        if (bulkShippingUpdateDataTransferObjects.SingleOrDefault(x=>x.OrderId == orderId) != null)
                            continue;

                        if (orderId.HasValue && parseErrors.All(x => x.Key != orderId.ToString()))
                            parseErrors.Add(orderId.ToString(), new List<string>());
                        else
                            parseErrors.Add("no-supplied-id", new List<string>());

                        var pv = new BulkShippingUpdateDataTransferObject();

                        if (file.GetField<string>(0).HasValue())
                            pv.OrderId = file.GetField<int>(0);
                        else
                            parseErrors["no-supplied-id"].Add("Order Id is required.");

                        if (file.GetField<string>(1).HasValue())
                            pv.ShippingMethod = file.GetField<string>(1);

                        if (file.GetField<string>(2).HasValue())
                            pv.TrackingNumber = file.GetField<string>(2).Trim();

                        bulkShippingUpdateDataTransferObjects.Add(pv);
                    }
                }
            }

            parseErrors = parseErrors.Where(x => x.Value.Any()).ToDictionary(pair => pair.Key, pair => pair.Value);
            
            return bulkShippingUpdateDataTransferObjects;
        }
示例#2
0
 public IEnumerable<string> GetErrors(BulkShippingUpdateDataTransferObject item)
 {
     var shippingMethod = _shippingMethodAdminService.GetAll().FirstOrDefault(x => x.DisplayName == item.ShippingMethod);
     if (shippingMethod == null)
         yield return string.Format("Shipping method {0} does not exist in the system.", item.ShippingMethod);
 }
示例#3
0
 public IEnumerable<string> GetErrors(BulkShippingUpdateDataTransferObject item)
 {
     if (_orderService.Get(item.OrderId) == null)
         yield return string.Format("Order {0} not present within the system.", item.OrderId);
 }