public ActionResult ImportStep2(ChatFAQResponseItemImportStep1VM 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)
            ChatFAQResponseItemImportStep2VM preImportCheckResult = new ChatFAQResponseItemImportStep2VM();

            preImportCheckResult = preImportCheckResultVM.ImportStep2VM;

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

            postImportResult = chatFAQResponseItemRepository.Import(
                preImportCheckResult.FileBytes,
                preImportCheckResultVM.ChatFAQResponseGroupId
                );

            postImportResult.ChatFAQResponseGroupId = preImportCheckResultVM.ChatFAQResponseGroupId;
            TempData["PostImportResult"]            = postImportResult;

            //Pass Results to Next Page
            return(RedirectToAction("ImportStep3"));
        }
        public ActionResult ImportStep3()
        {
            //Display Results of Import
            ChatFAQResponseItemImportStep3VM cdrPostImportResult = new ChatFAQResponseItemImportStep3VM();

            cdrPostImportResult = (ChatFAQResponseItemImportStep3VM)TempData["PostImportResult"];

            ChatFAQResponseGroup chatFAQResponseGroup = new ChatFAQResponseGroup();

            chatFAQResponseGroup = chatFAQResponseGroupRepository.GetGroup(cdrPostImportResult.ChatFAQResponseGroupId);
            cdrPostImportResult.ChatFAQResponseGroup = chatFAQResponseGroup;

            return(View(cdrPostImportResult));
        }
        public ChatFAQResponseItemImportStep3VM Import(byte[] FileBytes, int chatFAQResponseGroupId)
        {
            System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
            string fileToText            = fileToText = enc.GetString(FileBytes);

            ChatFAQResponseItemImportStep3VM cdrPostImportResult = new ChatFAQResponseItemImportStep3VM();

            // Create the xml document container, this will be used to store the data after the checks
            XmlDocument doc = new XmlDocument();

            //Prepare a list of error messages
            List <string> returnMessages = new List <string>();

            //Split the CSV into lines
            string[] lines = fileToText.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            //Validate CSV Lines
            ValidateLines(ref doc, lines, ref returnMessages);

            //DB Check
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            var output = (from n in db.spDesktopDataAdmin_UpdateChatFAQResponseItems_v1(
                              chatFAQResponseGroupId,
                              System.Xml.Linq.XElement.Parse(doc.OuterXml),
                              adminUserGuid)
                          select n).ToList();

            int addedItemCount = 0;

            foreach (spDesktopDataAdmin_UpdateChatFAQResponseItems_v1Result message in output)
            {
                returnMessages.Add(message.MessageText.ToString());
            }

            cdrPostImportResult.ReturnMessages = returnMessages;
            cdrPostImportResult.AddedItemCount = addedItemCount;

            return(cdrPostImportResult);
        }