//Add Data From Linked Tables for Display
        public void EditItemForDisplay(ChatFAQResponseItem chatFAQResponseItem)
        {
            //ChatMessageFAQName
            if (chatFAQResponseItem.ChatMessageFAQId > 0)
            {
                ChatMessageFAQRepository chatMessageFAQRepository = new ChatMessageFAQRepository();
                ChatMessageFAQ           chatMessageFAQ           = chatMessageFAQRepository.GetChatMessageFAQ(chatFAQResponseItem.ChatMessageFAQId);
                if (chatMessageFAQ != null)
                {
                    chatFAQResponseItem.ChatMessageFAQName = chatMessageFAQ.ChatMessageFAQName;
                }
            }

            //Set LanguageName to en-gb
            LanguageRepository languageRepository = new LanguageRepository();
            Language           language           = languageRepository.GetLanguage("en-GB");

            if (language != null)
            {
                chatFAQResponseItem.LanguageCode = language.LanguageCode;
                chatFAQResponseItem.LanguageName = language.LanguageName;
            }
        }
        private void ValidateLines(ref XmlDocument doc, string[] lines, ref List <string> returnMessages)
        {
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);

            doc.AppendChild(dec);
            XmlElement root = doc.CreateElement("ChatFAQResponseItems");

            doc.AppendChild(root);

            string returnMessage;

            int i = 0;

            //Store Valid ClientSubUnits
            List <int> validChatMessageFAQIds   = new List <int>();
            List <int> invalidChatMessageFAQIds = new List <int>();

            //loop through CSV lines
            foreach (string line in lines)
            {
                i++;

                if (i > 1)                 //ignore first line with titles
                {
                    Regex    csvParser = new Regex(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))");
                    String[] cells     = csvParser.Split(line);

                    //extract the data items from the file
                    string chatMessageFAQIdValue          = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[0]));                            //Required
                    string chatFAQResponseItemDescription = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[1]));                            //Required

                    //Build the XML Element for items
                    XmlElement xmlChatFAQResponseItem = doc.CreateElement("ChatFAQResponseItem");

                    //Validate data

                    /* ChatMessageFAQId */
                    int chatMessageFAQId = 0;

                    //Required
                    if (string.IsNullOrEmpty(chatMessageFAQIdValue) == true || !int.TryParse(chatMessageFAQIdValue, out chatMessageFAQId))
                    {
                        returnMessage = "Row " + i + ": ChatMessageFAQId is missing. Please provide a Chat Message FAQ Id";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }
                    else
                    {
                        bool existingValidChatMessageFAQId   = validChatMessageFAQIds.Contains(chatMessageFAQId);
                        bool existingInvalidChatMessageFAQId = invalidChatMessageFAQIds.Contains(chatMessageFAQId);

                        //Check Chat Message FAQ Id is valid
                        if (existingInvalidChatMessageFAQId)
                        {
                            //Error: Chat Message FAQ Id is invalid
                            returnMessage = string.Format("Row " + i + ": ChatMessageFAQId {0} is invalid. Please provide a valid Chat Message FAQ Id", chatMessageFAQId.ToString());
                            if (!returnMessages.Contains(returnMessage))
                            {
                                returnMessages.Add(returnMessage);
                            }
                        }
                        else if (existingValidChatMessageFAQId)
                        {
                            //Error: Chat Message FAQ Id is duplicated in file
                            returnMessage = string.Format("Row " + i + ": ChatMessageFAQId {0} is not unique. Please remove duplicate Chat Message FAQ Id", chatMessageFAQId.ToString());
                            if (!returnMessages.Contains(returnMessage))
                            {
                                returnMessages.Add(returnMessage);
                            }
                        }
                        else
                        {
                            //Check if valid Chat Message FAQ
                            ChatMessageFAQRepository chatMessageFAQRepository = new ChatMessageFAQRepository();
                            ChatMessageFAQ           chatMessageFAQ           = chatMessageFAQRepository.GetChatMessageFAQ(chatMessageFAQId);

                            //Error: Chat Message FAQ Id is invalid
                            if (chatMessageFAQ == null)
                            {
                                returnMessage = string.Format("Row " + i + ": ChatMessageFAQId {0} is invalid. Please provide a valid Chat Message FAQ Id", chatMessageFAQId.ToString());
                                if (!returnMessages.Contains(returnMessage))
                                {
                                    returnMessages.Add(returnMessage);
                                }

                                if (!invalidChatMessageFAQIds.Contains(chatMessageFAQId))
                                {
                                    invalidChatMessageFAQIds.Add(chatMessageFAQId);
                                }
                            }
                            else
                            {
                                validChatMessageFAQIds.Add(chatMessageFAQId);
                            }
                        }
                    }

                    XmlElement xmlChatMessageFAQId = doc.CreateElement("ChatMessageFAQId");
                    xmlChatMessageFAQId.InnerText = chatMessageFAQId.ToString();
                    xmlChatFAQResponseItem.AppendChild(xmlChatMessageFAQId);

                    //ChatFAQResponseItemDescription
                    string dataRegex = @"^([À-ÿ\w\s\/\*\-\.\(\)\,\u0022\“\'\%\$\=\+\?\!\:\;\@\<\>\""]+)";

                    if (string.IsNullOrEmpty(chatFAQResponseItemDescription.Trim()))
                    {
                        //Error: ChatFAQResponseItemDescription is missing
                        returnMessage = string.Format("Row " + i + ": ChatFAQResponseItemDescription is missing. Please provide a Chat FAQ Response");
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }
                    else if (chatFAQResponseItemDescription.Length > 400)
                    {
                        //Error: ChatFAQResponseItemDescription is too long
                        returnMessage = string.Format("Row " + i + ": ChatFAQResponseItemDescription contains more than 400 characters. Please provide a valid Chat FAQ Response");
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }
                    else if (!Regex.Match(chatFAQResponseItemDescription, dataRegex).Success)
                    {
                        //Error: ChatFAQResponseItemDescription contains invalid characters
                        returnMessage = string.Format("Row " + i + ": ChatFAQResponseItemDescription contains invalid special characters. Please provide a valid Chat FAQ Response");
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    XmlElement xmlChatFAQResponseItemDescription = doc.CreateElement("ChatFAQResponseItemDescription");
                    xmlChatFAQResponseItemDescription.InnerText = chatFAQResponseItemDescription;
                    xmlChatFAQResponseItem.AppendChild(xmlChatFAQResponseItemDescription);

                    //Attach the XML Element for an item to the Document
                    root.AppendChild(xmlChatFAQResponseItem);
                }
            }

            if (i < 2)
            {
                returnMessage = "There is no data in the file";
                returnMessages.Add(returnMessage);
            }
        }