Esempio n. 1
0
        public JsonResult OffAirbnbUpload(HttpPostedFileBase excelFile)
        {
            var    provider      = new OffAirbnbImportProvider(_dbContext);
            var    filename      = "off-airbnb-import.xlsx";
            string excelPath     = Path.Combine(Helpers.UrlHelper.DataRootUrl(), filename);
            int    result        = provider.ImportExcel(excelFile.InputStream);
            string resultMessage = string.Empty;

            if (result == 0)
            {
                resultMessage = "There is no data in the file.";
            }
            else if (result > 0)
            {
                resultMessage = string.Format("There were {0:d} Reservations processed and saved to database.", result);
            }
            else
            {
                resultMessage = string.Format("There were {0:d} Errors found in the file. No data is saved to database.", -result);
            }

            var resultJson = new
            {
                Status  = result > 0 ? 1 : (result == 0 ? 0 : -1),
                Message = resultMessage
            };

            return(Json(resultJson, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        private int ImportOffAirbnbExcel(Stream dataStream)
        {
            try
            {
                // speed up bulk insertion
                _dbContext.Configuration.AutoDetectChangesEnabled = false;
                _dbContext.Configuration.ValidateOnSaveEnabled    = false;

                var dataProvider = new OffAirbnbImportProvider(_dbContext);
                return(dataProvider.ImportExcel(dataStream));
            }
            catch
            {
                throw;
            }
        }