public ActionResult ImportStep1(TeamOutOfOfficeGroupImportStep1WithFileVM csvfile)
        {
            if (!ModelState.IsValid)
            {
                return(View(csvfile));
            }
            string fileExtension = Path.GetExtension(csvfile.File.FileName);

            if (fileExtension != ".csv")
            {
                ModelState.AddModelError("file", "This is not a valid entry");
                return(View(csvfile));
            }

            if (csvfile.File.ContentLength > 0)
            {
                TeamOutOfOfficeGroupImportStep2VM preImportCheckResult = new TeamOutOfOfficeGroupImportStep2VM();
                List <string> returnMessages = new List <string>();

                preImportCheckResult = teamOutOfOfficeGroupRepository.PreImportCheck(csvfile.File, csvfile.ClientSubUnitGuid);

                TeamOutOfOfficeGroupImportStep1VM preImportCheckResultVM = new TeamOutOfOfficeGroupImportStep1VM();
                preImportCheckResultVM.ImportStep2VM     = preImportCheckResult;
                preImportCheckResultVM.ClientSubUnitGuid = csvfile.ClientSubUnitGuid;

                TempData["PreImportCheckResultVM"] = preImportCheckResultVM;
                return(RedirectToAction("ImportStep2"));
            }

            return(View());
        }
        public ActionResult ImportStep2()
        {
            TeamOutOfOfficeGroupImportStep1VM preImportCheckResultVM = new TeamOutOfOfficeGroupImportStep1VM();

            preImportCheckResultVM = (TeamOutOfOfficeGroupImportStep1VM)TempData["PreImportCheckResultVM"];
            if (preImportCheckResultVM == null)
            {
                return(View("Error"));
            }

            return(View(preImportCheckResultVM));
        }
        public ActionResult ImportStep2(TeamOutOfOfficeGroupImportStep1VM preImportCheckResultVM)
        {
            if (preImportCheckResultVM.ImportStep2VM.IsValidData == false)
            {
                //Check JSON for valid messages
                if (preImportCheckResultVM.ImportStep2VM.ReturnMessages[0] != null)
                {
                    List <string> returnMessages = new List <string>();

                    var settings = new JsonSerializerSettings
                    {
                        StringEscapeHandling = StringEscapeHandling.EscapeHtml,
                    };

                    List <string> returnMessagesJSON = JsonConvert.DeserializeObject <List <string> >(preImportCheckResultVM.ImportStep2VM.ReturnMessages[0], settings);

                    foreach (string message in returnMessagesJSON)
                    {
                        string validMessage = Regex.Replace(message, @"[^À-ÿ\w\s&:._()\-]", "");

                        if (!string.IsNullOrEmpty(validMessage))
                        {
                            returnMessages.Add(validMessage);
                        }
                    }

                    preImportCheckResultVM.ImportStep2VM.ReturnMessages = returnMessages;
                }

                TempData["ErrorMessages"] = preImportCheckResultVM;

                return(RedirectToAction("ExportErrors"));
            }

            //PreImport Check Results (check has passed)
            TeamOutOfOfficeGroupImportStep2VM preImportCheckResult = new TeamOutOfOfficeGroupImportStep2VM();

            preImportCheckResult = preImportCheckResultVM.ImportStep2VM;

            //Do the Import, return results
            TeamOutOfOfficeGroupImportStep3VM postImportResult = new TeamOutOfOfficeGroupImportStep3VM();

            postImportResult = teamOutOfOfficeGroupRepository.Import(
                preImportCheckResult.FileBytes
                );

            TempData["PostImportResult"] = postImportResult;

            //Pass Results to Next Page
            return(RedirectToAction("ImportStep3"));
        }