Exemple #1
0
        public ActionResult ProcessCSV(SelectTypeVM vm)
        {
            _configurationService.MakeDropDownAndFirstFive(vm);

            if (vm.ColumnTypes.Values.Where(x => x != "").Count() < 2)
            {
                ModelState.AddModelError(string.Empty, "*You must select at least two variables");
                TempData["ViewData"]   = ViewData;
                TempData["ModelState"] = ModelState;
                ViewData = (ViewDataDictionary)TempData["ViewData"];
                return(View("SelectTypes", vm));
            }

            Dictionary <string, List <string> > invalidColumns = _parsingService.CheckForInvalidColumns(vm.ColumnTypes, vm.FirstFiveRows);

            if (invalidColumns.Count > 0)
            {
                ViewBag.Error          = "<p class='viewbag-error'>*Invalid data found* <br/>Did you mark a categorical variabal as numeral? </p>";
                TempData["ViewData"]   = ViewData;
                TempData["ModelState"] = ModelState;
                ViewData = (ViewDataDictionary)TempData["ViewData"];
                return(View("SelectTypes", vm));
            }


            Dictionary <string, List <string> > dictFile = _parsingService.CsvToDictionary(vm.Path);

            StatSummaryVM summaryVM = _summaryService.GetSummaryVM(dictFile, vm);

            summaryVM.CreatedOn = DateTime.Now;

            string userId = User.Identity.GetUserId();

            _summaryService.SaveStatSummary(summaryVM, userId);

            ViewBag.Saved = "true";

            return(View("Report", summaryVM));
        }