Esempio n. 1
0
        public IActionResult UploadCursusFile(UploadCursusFileViewModel uploadCursusViewModel, bool cbUseDateRange = true)
        {
            // Check if given UploadCursusFileViewModel model is valid
            if (!ModelState.IsValid)
            {
                return(View(uploadCursusViewModel));
            }

            if (!cbUseDateRange)
            {
                uploadCursusViewModel.StartDate = DateTime.MinValue;
                uploadCursusViewModel.EndDate   = DateTime.MaxValue;
            }

            ParsedCursusFileResultContainer parsedCursusFileResultContainer;

            try {
                parsedCursusFileResultContainer = _cursusFileParser.GetCursussenFromCursusFile(uploadCursusViewModel.CursusFile, uploadCursusViewModel.StartDate, uploadCursusViewModel.EndDate);
            } catch
            {
                return(View(uploadCursusViewModel));
            }
            // Check if we stumbled on errors
            if (parsedCursusFileResultContainer.ErrorMessages.Count > 0)
            {
                ViewData[CURSUS_FILE_ERRORS_TITLE] = $"{parsedCursusFileResultContainer.ErrorMessages.Count} fout(en) gevonden:";
                foreach (var errorMessage in parsedCursusFileResultContainer.ErrorMessages)
                {
                    ModelState.AddModelError(CURSUS_FILE_ERRORS, errorMessage);
                }
                return(View(uploadCursusViewModel));
            }

            // Check if we stumbled on duplicates
            if (parsedCursusFileResultContainer.DuplicateCursussen.Count > 0)
            {
                ViewData[CURSUS_FILE_DUPLICATES_TITLE] = $"{parsedCursusFileResultContainer.DuplicateCursussen.Count} dubbele cursus(sen) gevonden:";
                foreach (var duplicate in parsedCursusFileResultContainer.DuplicateCursussen)
                {
                    ModelState.AddModelError(CURSUS_FILE_DUPLICATES, $"Duplicaat: {duplicate.CursusCode} met datum: {duplicate.StartDate.Date.ToString("dd/MM/yyyy")}");
                }
            }

            uploadCursusViewModel.CursusImportedFeedbackViewModel = new CursusImportedFeedbackViewModel("Aantal cursus(sen) toegevoegd", parsedCursusFileResultContainer.ParsedCursussen.Count);

            // Post valid cursussen
            foreach (var cursus in parsedCursusFileResultContainer.ParsedCursussen)
            {
                ModelState.AddModelError(CURSUS_FILE_IMPORTED, $"Titel: {cursus.Title}, Cursuscode: {cursus.CursusCode}, Startdatum: {cursus.StartDate.Date.ToString("dd/MM/yyyy")}");
                _casService.Post(cursus);
            }

            return(View(uploadCursusViewModel));
        }
Esempio n. 2
0
        public IActionResult UploadCursusFile()
        {
            var model = new UploadCursusFileViewModel();

            return(View(model));
        }