Example #1
0
 public PostResponse PricePush(FantasticPriceModel model)
 {
     return(PricePush(
                model.ListingId,
                model.StartDate,
                model.EndDate,
                model.IsAvailable,
                model.Price.Value,
                model.Note
                ));
 }
        private List <FantasticPriceModel> ParsePriceRow(ExcelRange cells, int row, int totalCols, List <int> listingIds)
        {
            var      priceModels = new List <FantasticPriceModel>();
            DateTime startDate   = new DateTime(2050, 12, 31); // arbitrary future date
            int      index       = 0;

            for (int col = _dateCol; col <= totalCols; col++) // excel column index starts from 1
            {
                if (col == _dateCol)
                {
                    if (DateTime.TryParseExact(cells[row, col].Text, "MM/dd/yy", new CultureInfo("en-US"), DateTimeStyles.None, out startDate) == false)
                    {
                        throw new Exception(string.Format("Input error at row {0:d} for date.", row));
                    }
                }
                else
                {
                    double price = 0;
                    if (double.TryParse(cells[row, col].Text, out price) == true)
                    {
                        var priceModel = new FantasticPriceModel
                        {
                            ListingId   = listingIds[index++],
                            StartDate   = startDate,
                            EndDate     = startDate,
                            IsAvailable = true,
                            Price       = price,
                            Note        = null
                        };
                        priceModels.Add(priceModel);
                    }
                    else
                    {
                        throw new Exception(string.Format("Input error at row {0:d} for price.", row));
                    }
                }
            }
            return(priceModels);
        }