private List <FantasticCustomStayModel> ParseMinStayRow(ExcelRange cells, int row, int totalCols, List <int> listingIds)
        {
            var      models    = new List <FantasticCustomStayModel>();
            DateTime startDate = new DateTime(2050, 12, 31); // arbitrary future date
            int      index     = 0;

            try
            {
                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
                    {
                        int minStay = 0;
                        if (int.TryParse(cells[row, col].Text, out minStay) == true)
                        {
                            var model = new FantasticCustomStayModel
                            {
                                ListingId = listingIds[index++],
                                StartDate = startDate,
                                EndDate   = startDate,
                                MinStay   = minStay
                            };
                            models.Add(model);
                        }
                        else
                        {
                            throw new Exception(string.Format("Input error at row {0:d} for minimum stay.", row));
                        }
                    }
                }
                return(models);
            }
            catch
            {
                throw;
            }
        }
Esempio n. 2
0
 public PostResponse CustomStayUpdate(FantasticCustomStayModel model)
 {
     return(CustomStay(model.ListingId, model.StartDate, model.EndDate, model.MinStay));
 }