Example #1
0
        public ActionResult ImportStep2(PolicyCountryImportStep1VM 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)
            PolicyCountryImportStep2VM preImportCheckResult = new PolicyCountryImportStep2VM();

            preImportCheckResult = preImportCheckResultVM.ImportStep2VM;

            //Do the Import, return results
            PolicyCountryImportStep3VM cdrPostImportResult = new PolicyCountryImportStep3VM();

            cdrPostImportResult = policyCountryGroupItemRepository.Import(
                preImportCheckResult.FileBytes,
                preImportCheckResultVM.PolicyGroupId
                );

            cdrPostImportResult.PolicyGroupId = preImportCheckResultVM.PolicyGroupId;
            TempData["CdrPostImportResult"]   = cdrPostImportResult;

            //Pass Results to Next Page
            return(RedirectToAction("ImportStep3"));
        }
Example #2
0
        public ActionResult ImportStep2()
        {
            PolicyCountryImportStep1VM preImportCheckResultVM = new PolicyCountryImportStep1VM();

            preImportCheckResultVM = (PolicyCountryImportStep1VM)TempData["PreImportCheckResultVM"];

            PolicyGroup policyGroup = new PolicyGroup();

            policyGroup = policyGroupRepository.GetGroup(preImportCheckResultVM.PolicyGroupId);
            preImportCheckResultVM.PolicyGroup = policyGroup;

            return(View(preImportCheckResultVM));
        }
Example #3
0
        public ActionResult ImportStep1(PolicyCountryImportStep1WithFileVM csvfile)
        {
            //used for return only
            PolicyGroup policyGroup = new PolicyGroup();

            policyGroup         = policyGroupRepository.GetGroup(csvfile.PolicyGroupId);
            csvfile.PolicyGroup = policyGroup;


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

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

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

                preImportCheckResult = policyCountryGroupItemRepository.PreImportCheck(csvfile.File, csvfile.PolicyGroupId);

                PolicyCountryImportStep1VM preImportCheckResultVM = new PolicyCountryImportStep1VM();
                preImportCheckResultVM.PolicyGroup   = policyGroup;
                preImportCheckResultVM.ImportStep2VM = preImportCheckResult;
                preImportCheckResultVM.PolicyGroupId = csvfile.PolicyGroupId;

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

            return(View());
        }