Example #1
0
        public CsvFileInfo GetCsvColumns(ImportForm file)
        {
            string path;

            try
            {
                //path = _fileService.Save(file.File, "App_Data\\uploads");
                path = _fileService.Save(file.File);
            }
            catch (Exception e)
            {

                throw e;
            }
            var skip = file.FirstRowContainsColumnHeadings ? 1 : 0;
            var rawRows = GetRawRows(path);
            var dataRow = rawRows.First();
            return new CsvFileInfo
            {
                Name = Path.GetFileName(path),
                Path = path,
                Columns = dataRow.Select((t, i) => new CsvColumn
                {
                    Id = i,
                    Name = t.Value
                }).ToList(),
                Category = file.Category,
                Flag = file.Flag
            };
        }
Example #2
0
        public ActionResult Index(ImportForm importForm)
        {
            GetAccount();
            if (!ModelState.IsValid)
            {
                ViewBag.Categories = _xmlRepository.GetAllCategories();
                //ViewBag.Flags = _xmlRepository.GetAllFlags();
                return View();
                //return RedirectToAction("Index");
            }
            try
            {
                CsvFileInfo csvFileInfo = _importService.GetCsvColumns(importForm);
                csvFileInfo.FirstRowContainsColumnHeadings = importForm.FirstRowContainsColumnHeadings;
                TempData["CsvFileInfo"] = csvFileInfo;
                
                List<SelectListItem> selectListItems = GetFields();

                return View("ImportMap", new FieldMapperViewModel
                {
                    ColumnMaps = csvFileInfo.Columns,
                    Fields = selectListItems
                });
            }
            catch (Exception)
            {
                AddError("There is an error with importing CSV file,Please try again later.");
                return RedirectToAction("Index");
            }
        }