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);
            }
        }
        public ClientTopUnitImportStep3VM Import(byte[] FileBytes, string clientTopUnitGuid)
        {
            System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
            string fileToText            = fileToText = enc.GetString(FileBytes);

            ClientTopUnitImportStep3VM cdrPostImportResult = new ClientTopUnitImportStep3VM();
            List <string> returnMessages = new List <string>();

            // Create the xml document container, this will be used to store the data after the checks
            XmlDocument    doc = new XmlDocument();
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);

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

            doc.AppendChild(root);

            int i = 0;

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

            //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 addressLocationName = CWTStringHelpers.UnescapeQuotes(cells[0]); //Required
                    string firstAddressLine    = CWTStringHelpers.UnescapeQuotes(cells[1]); //Required
                    string secondAddressLine   = CWTStringHelpers.UnescapeQuotes(cells[2]) ?? "";
                    string cityName            = CWTStringHelpers.UnescapeQuotes(cells[3]); //Required
                    string postalCode          = CWTStringHelpers.UnescapeQuotes(cells[4]); //Required
                    string countryCode         = cells[5];                                  //Required (e.g.US)
                    string stateProvinceName   = cells[6];                                  //Required if CountryCode is in the StateProvince table (should contain valid StateProvinceCode)
                    string latitudeDecimal     = cells[7];                                  //Required
                    string longitudeDecimal    = cells[8];                                  //Required
                    string ranking             = cells[9] ?? "";

                    //Build the XML Element for items

                    XmlElement xmlClientTopUnitLocationItem = doc.CreateElement("PHCRIG");

                    XmlElement xmlAddressLocationName = doc.CreateElement("AddressLocationName");
                    xmlAddressLocationName.InnerText = addressLocationName;
                    xmlClientTopUnitLocationItem.AppendChild(xmlAddressLocationName);

                    XmlElement xmlFirstAddressLine = doc.CreateElement("FirstAddressLine");
                    xmlFirstAddressLine.InnerText = firstAddressLine;
                    xmlClientTopUnitLocationItem.AppendChild(xmlFirstAddressLine);

                    XmlElement xmlSecondAddressLine = doc.CreateElement("SecondAddressLine");
                    xmlSecondAddressLine.InnerText = secondAddressLine;
                    xmlClientTopUnitLocationItem.AppendChild(xmlSecondAddressLine);

                    XmlElement xmlCityName = doc.CreateElement("CityName");
                    xmlCityName.InnerText = cityName;
                    xmlClientTopUnitLocationItem.AppendChild(xmlCityName);

                    XmlElement xmlPostalCode = doc.CreateElement("PostalCode");
                    xmlPostalCode.InnerText = postalCode;
                    xmlClientTopUnitLocationItem.AppendChild(xmlPostalCode);

                    XmlElement xmlCountryCode = doc.CreateElement("CountryCode");
                    xmlCountryCode.InnerText = countryCode;
                    xmlClientTopUnitLocationItem.AppendChild(xmlCountryCode);

                    if (stateProvinceName.ToLower() != "null" && !string.IsNullOrEmpty(stateProvinceName))
                    {
                        XmlElement xmlStateProvinceName = doc.CreateElement("StateProvinceName");
                        xmlStateProvinceName.InnerText = stateProvinceName;
                        xmlClientTopUnitLocationItem.AppendChild(xmlStateProvinceName);
                    }

                    XmlElement xmlLatitudeDecimal = doc.CreateElement("LatitudeDecimal");
                    xmlLatitudeDecimal.InnerText = latitudeDecimal;
                    xmlClientTopUnitLocationItem.AppendChild(xmlLatitudeDecimal);

                    XmlElement xmlLongitudeDecimal = doc.CreateElement("LongitudeDecimal");
                    xmlLongitudeDecimal.InnerText = longitudeDecimal;
                    xmlClientTopUnitLocationItem.AppendChild(xmlLongitudeDecimal);

                    int  validRanking;
                    bool isRankingNumerical = Int32.TryParse(ranking, out validRanking);
                    if (isRankingNumerical && ranking.ToLower() != "null" && !string.IsNullOrEmpty(ranking))
                    {
                        XmlElement xmlRanking = doc.CreateElement("Ranking");
                        xmlRanking.InnerText = ranking;
                        xmlClientTopUnitLocationItem.AppendChild(xmlRanking);
                    }

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

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

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

            int deletedItemCount = 0;
            int addedItemCount   = 0;

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

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

            return(cdrPostImportResult);
        }
コード例 #3
0
        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("TeamOutOfOfficeGroups");

            doc.AppendChild(root);

            string returnMessage;

            int i = 0;

            //Store Valid ClientSubUnits
            List <string> validClientSubUnitGuids   = new List <string>();
            List <string> invalidClientSubUnitGuids = new List <string>();

            //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 clientSubUnitGuid        = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[0]));                          //Required
                    string primaryBackupTeamValue   = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[1]));                          //Required
                    string secondaryBackupTeamValue = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[2]));
                    string tertiaryBackupTeamValue  = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[3]));

                    //Build the XML Element for items

                    XmlElement xmlTeamOutOfOfficeGroupItem = doc.CreateElement("TeamOutOfOfficeGroupItem");

                    //Validate data

                    /* Client SubUnit Guid */

                    //Required
                    if (string.IsNullOrEmpty(clientSubUnitGuid) == true)
                    {
                        returnMessage = "Row " + i + ": Client SubUnit Guid is missing. Please provide a Client SubUnit Guid";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }
                    else
                    {
                        bool existingValidClient   = validClientSubUnitGuids.Contains(clientSubUnitGuid);
                        bool existingInvalidClient = invalidClientSubUnitGuids.Contains(clientSubUnitGuid);

                        //Check ClientSubUnit is valid
                        if (existingInvalidClient)
                        {
                            //Error: ClientSubUnit is invalid
                            returnMessage = string.Format("Row " + i + ": ClientSubUnitGuid {0} is invalid. Please provide a valid Client SubUnit Guid", clientSubUnitGuid);
                            if (!returnMessages.Contains(returnMessage))
                            {
                                returnMessages.Add(returnMessage);
                            }
                        }
                        else if (existingValidClient)
                        {
                            //No processing required as already marked as valid
                        }
                        else
                        {
                            ClientSubUnitRepository clientSubUnitRepository = new ClientSubUnitRepository();
                            ClientSubUnit           clientSubUnit           = clientSubUnitRepository.GetClientSubUnit(clientSubUnitGuid);
                            if (clientSubUnit == null)
                            {
                                //Error: ClientSubUnit is invalid
                                returnMessage = string.Format("Row " + i + ": ClientSubUnitGuid {0} is invalid. Please provide a valid Client SubUnit Guid", clientSubUnitGuid);
                                if (!returnMessages.Contains(returnMessage))
                                {
                                    returnMessages.Add(returnMessage);
                                }

                                if (!invalidClientSubUnitGuids.Contains(clientSubUnitGuid))
                                {
                                    invalidClientSubUnitGuids.Add(clientSubUnitGuid);
                                }
                            }
                            else
                            {
                                //We have a valid Client SubUnit, now check TeamOutOfOfficeGroupClientSubUnit
                                List <TeamOutOfOfficeGroupClientSubUnit> teamOutOfOfficeGroupClientSubUnits = db.TeamOutOfOfficeGroupClientSubUnits.Where(x => x.ClientSubUnitGuid == clientSubUnitGuid).ToList();
                                if (teamOutOfOfficeGroupClientSubUnits.Count > 0)
                                {
                                    //Error: ClientSubUnit relationship already exists
                                    returnMessage = string.Format("Row " + i + ": ClientSubUnitGuid {0} is not unique. Please update existing Team Out of Office Group", clientSubUnitGuid);
                                    if (!returnMessages.Contains(returnMessage))
                                    {
                                        returnMessages.Add(returnMessage);
                                    }

                                    if (!invalidClientSubUnitGuids.Contains(clientSubUnitGuid))
                                    {
                                        invalidClientSubUnitGuids.Add(clientSubUnitGuid);
                                    }
                                }
                                else
                                {
                                    //ClientSubUnitGuid must have an entry in the IsPrimaryTeamForSub table
                                    List <IsPrimaryTeamForSub> primaryTeamForClientSubUnits = db.IsPrimaryTeamForSubs.Where(x => x.ClientSubUnitGuid == clientSubUnitGuid).ToList();
                                    if (primaryTeamForClientSubUnits.Count == 0)
                                    {
                                        //Error: ClientSubUnit relationship already exists
                                        returnMessage = string.Format("Row " + i + ": ClientSubUnitGuid {0} does not have a Primary Team setup. Please complete in Client Wizard for this ClientSubUnitGuid", clientSubUnitGuid);
                                        if (!returnMessages.Contains(returnMessage))
                                        {
                                            returnMessages.Add(returnMessage);
                                        }

                                        if (!invalidClientSubUnitGuids.Contains(clientSubUnitGuid))
                                        {
                                            invalidClientSubUnitGuids.Add(clientSubUnitGuid);
                                        }
                                    }
                                    else
                                    {
                                        if (!validClientSubUnitGuids.Contains(clientSubUnitGuid))
                                        {
                                            validClientSubUnitGuids.Add(clientSubUnitGuid);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    XmlElement xmlClientSubUnitGuid = doc.CreateElement("ClientSubUnitGuid");
                    xmlClientSubUnitGuid.InnerText = clientSubUnitGuid;
                    xmlTeamOutOfOfficeGroupItem.AppendChild(xmlClientSubUnitGuid);

                    //Primary Backup Team
                    int primaryBackupTeamId = 0;
                    if (string.IsNullOrEmpty(primaryBackupTeamValue) || !Int32.TryParse(primaryBackupTeamValue, out primaryBackupTeamId))
                    {
                        //Error: PrimaryBackupTeamId is invalid
                        returnMessage = string.Format("Row " + i + ": PrimaryBackupTeamId is missing. Please provide a Team Id", clientSubUnitGuid);
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }
                    else
                    {
                        TeamRepository teamRepository    = new TeamRepository();
                        Team           primaryBackupTeam = teamRepository.GetTeam(primaryBackupTeamId);
                        if (primaryBackupTeam == null)
                        {
                            //Error: PrimaryBackupTeamId is invalid
                            returnMessage = string.Format("Row " + i + ": PrimaryBackupTeamId {0} is invalid. Please provide a valid Team Id", primaryBackupTeamValue);
                            if (!returnMessages.Contains(returnMessage))
                            {
                                returnMessages.Add(returnMessage);
                            }
                        }
                    }

                    XmlElement xmlPrimaryBackupTeamId = doc.CreateElement("PrimaryBackupTeamId");
                    xmlPrimaryBackupTeamId.InnerText = primaryBackupTeamValue;
                    xmlTeamOutOfOfficeGroupItem.AppendChild(xmlPrimaryBackupTeamId);

                    //Secondary Backup Team
                    if (!string.IsNullOrEmpty(secondaryBackupTeamValue))
                    {
                        int secondaryBackupTeamId = 0;
                        if (!Int32.TryParse(secondaryBackupTeamValue, out secondaryBackupTeamId))
                        {
                            //Error: SecondaryBackupTeamId is invalid
                            returnMessage = string.Format("Row " + i + ": SecondaryBackupTeamId {0} is invalid. Please provide a valid Team Id", secondaryBackupTeamValue);
                            if (!returnMessages.Contains(returnMessage))
                            {
                                returnMessages.Add(returnMessage);
                            }
                        }
                        else
                        {
                            TeamRepository teamRepository      = new TeamRepository();
                            Team           secondaryBackupTeam = teamRepository.GetTeam(secondaryBackupTeamId);
                            if (secondaryBackupTeam == null)
                            {
                                //Error: SecondaryBackupTeamId is invalid
                                returnMessage = string.Format("Row " + i + ": SecondaryBackupTeamId {0} is invalid. Please provide a valid Team Id", secondaryBackupTeamValue);
                                if (!returnMessages.Contains(returnMessage))
                                {
                                    returnMessages.Add(returnMessage);
                                }
                            }
                        }
                    }

                    XmlElement xmlSecondaryBackupTeamId = doc.CreateElement("SecondaryBackupTeamId");
                    xmlSecondaryBackupTeamId.InnerText = secondaryBackupTeamValue;
                    xmlTeamOutOfOfficeGroupItem.AppendChild(xmlSecondaryBackupTeamId);

                    //Tertiary Backup Team
                    if (!string.IsNullOrEmpty(tertiaryBackupTeamValue))
                    {
                        int tertiaryBackupTeamId = 0;
                        if (!Int32.TryParse(tertiaryBackupTeamValue, out tertiaryBackupTeamId))
                        {
                            //Error: TertiaryBackupTeamId is invalid
                            returnMessage = string.Format("Row " + i + ": TertiaryBackupTeamId {0} is invalid. Please provide a valid Team Id", tertiaryBackupTeamValue);
                            if (!returnMessages.Contains(returnMessage))
                            {
                                returnMessages.Add(returnMessage);
                            }
                        }
                        else
                        {
                            TeamRepository teamRepository     = new TeamRepository();
                            Team           tertiaryBackupTeam = teamRepository.GetTeam(tertiaryBackupTeamId);
                            if (tertiaryBackupTeam == null)
                            {
                                //Error: TertiaryBackupTeamId is invalid
                                returnMessage = string.Format("Row " + i + ": TertiaryBackupTeamId {0} is invalid. Please provide a valid Team Id", tertiaryBackupTeamValue);
                                if (!returnMessages.Contains(returnMessage))
                                {
                                    returnMessages.Add(returnMessage);
                                }
                            }
                        }
                    }

                    XmlElement xmlTertiaryBackupTeamId = doc.CreateElement("TertiaryBackupTeamId");
                    xmlTertiaryBackupTeamId.InnerText = tertiaryBackupTeamValue;
                    xmlTeamOutOfOfficeGroupItem.AppendChild(xmlTertiaryBackupTeamId);

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

            if (i == 0)
            {
                returnMessage = "There is no data in the file";
                returnMessages.Add(returnMessage);
            }
        }
        public ClientTopUnitImportStep2VM PreImportCheck(HttpPostedFileBase file, string clientTopUnitGuid)
        {
            //convert file to string so that we can parse
            int length = file.ContentLength;

            byte[] tempFile = new byte[length];
            file.InputStream.Read(tempFile, 0, length);
            byte[] array = tempFile.ToArray();
            System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
            string fileToText            = fileToText = enc.GetString(array);

            // Create the xml document container, this will be used to store the data after the checks
            XmlDocument    doc = new XmlDocument();
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);

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

            doc.AppendChild(root);

            List <string> returnMessages = new List <string>();
            string        returnMessage;
            int           i = 0;

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

            //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 addressLocationName = CWTStringHelpers.UnescapeQuotes(cells[0]); //Required
                    string firstAddressLine    = CWTStringHelpers.UnescapeQuotes(cells[1]); //Required
                    string secondAddressLine   = CWTStringHelpers.UnescapeQuotes(cells[2]) ?? "";
                    string cityName            = CWTStringHelpers.UnescapeQuotes(cells[3]); //Required
                    string postalCode          = CWTStringHelpers.UnescapeQuotes(cells[4]); //Required
                    string countryCode         = cells[5];                                  //Required (e.g.US)
                    string stateProvinceName   = cells[6];                                  //Required if CountryCode is in the StateProvince table (should contain valid StateProvinceCode)
                    string latitudeDecimal     = cells[7];                                  //Required
                    string longitudeDecimal    = cells[8];                                  //Required
                    string ranking             = cells[9] ?? "";

                    //Build the XML Element for items

                    XmlElement xmlClientTopUnitLocationItem = doc.CreateElement("PHCRIG");

                    XmlElement xmlAddressLocationName = doc.CreateElement("AddressLocationName");
                    xmlAddressLocationName.InnerText = addressLocationName;
                    xmlClientTopUnitLocationItem.AppendChild(xmlAddressLocationName);

                    XmlElement xmlFirstAddressLine = doc.CreateElement("FirstAddressLine");
                    xmlFirstAddressLine.InnerText = firstAddressLine;
                    xmlClientTopUnitLocationItem.AppendChild(xmlFirstAddressLine);

                    XmlElement xmlSecondAddressLine = doc.CreateElement("SecondAddressLine");
                    xmlSecondAddressLine.InnerText = secondAddressLine;
                    xmlClientTopUnitLocationItem.AppendChild(xmlSecondAddressLine);

                    XmlElement xmlCityName = doc.CreateElement("CityName");
                    xmlCityName.InnerText = cityName;
                    xmlClientTopUnitLocationItem.AppendChild(xmlCityName);

                    XmlElement xmlPostalCode = doc.CreateElement("PostalCode");
                    xmlPostalCode.InnerText = postalCode;
                    xmlClientTopUnitLocationItem.AppendChild(xmlPostalCode);

                    XmlElement xmlCountryCode = doc.CreateElement("CountryCode");
                    xmlCountryCode.InnerText = countryCode;
                    xmlClientTopUnitLocationItem.AppendChild(xmlCountryCode);

                    XmlElement xmlStateProvinceName = doc.CreateElement("StateProvinceName");
                    xmlStateProvinceName.InnerText = stateProvinceName;
                    xmlClientTopUnitLocationItem.AppendChild(xmlStateProvinceName);

                    XmlElement xmlLatitudeDecimal = doc.CreateElement("LatitudeDecimal");
                    xmlLatitudeDecimal.InnerText = latitudeDecimal;
                    xmlClientTopUnitLocationItem.AppendChild(xmlLatitudeDecimal);

                    XmlElement xmlLongitudeDecimal = doc.CreateElement("LongitudeDecimal");
                    xmlLongitudeDecimal.InnerText = longitudeDecimal;
                    xmlClientTopUnitLocationItem.AppendChild(xmlLongitudeDecimal);

                    //Validate data
                    if (string.IsNullOrEmpty(addressLocationName) == true)
                    {
                        returnMessage = "Row " + i + ": AddressLocationName is missing. Please provide a Client Location Name";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    if (string.IsNullOrEmpty(firstAddressLine) == true)
                    {
                        returnMessage = "Row " + i + ": FirstAddressLine is missing. Please provide a First Address Line";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    if (string.IsNullOrEmpty(cityName) == true)
                    {
                        returnMessage = "Row " + i + ": CityName is missing. Please provide a City Name";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    if (string.IsNullOrEmpty(postalCode) == true)
                    {
                        returnMessage = "Row " + i + ": PostalCode is missing. Please provide a Postal Code";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    if (string.IsNullOrEmpty(countryCode) == true)
                    {
                        returnMessage = "Row " + i + ": CountryCode is missing. Please provide a valid Country Code";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    if (string.IsNullOrEmpty(latitudeDecimal) == true)
                    {
                        returnMessage = "Row " + i + ": Latitude is missing. Please provide a valid Latitude";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    if (string.IsNullOrEmpty(longitudeDecimal) == true)
                    {
                        returnMessage = "Row " + i + ": Longitude is missing. Please provide a valid Longitude";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //AddressLocationName is freeform text and will allow up to 150 alphanumeric and allowable special characters.
                    if (addressLocationName.Length > 150)
                    {
                        returnMessage = "Row " + i + ": AddressLocationName contains more than 150 characters. Please provide a valid Address Location Name";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //AddressLocationName allowable special characters are: space, dash, underscore, right and left parentheses, period, apostrophe (O’Reily), ampersand and accented characters.
                    string addressLocationNamePattern = @"^[À-ÿ\w\s-()\.\&\'\’_]+$";
                    if (!Regex.IsMatch(addressLocationName, addressLocationNamePattern, RegexOptions.IgnoreCase))
                    {
                        returnMessage = "Row " + i + ": AddressLocationName contains invalid special characters. Please provide a Address Location Name";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //FirstAddressLine is freeform text and will allow up to 150 alphanumeric and allowable special characters.
                    if (firstAddressLine.Length > 150)
                    {
                        returnMessage = "Row " + i + ": FirstAddressLine contains more than 150 characters. Please provide a valid First Address Line";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //FirstAddressLine allowable special characters are: space, dash, underscore, right and left parentheses, period, apostrophe (O’Reily), ampersand and accented characters.
                    string firstAddressLinePattern = @"^([À-ÿ\w\s-()\*\.\&\'\’_\,\:\,\°\#\\\/]+)$";

                    if (!Regex.IsMatch(firstAddressLine, firstAddressLinePattern, RegexOptions.IgnoreCase))
                    {
                        returnMessage = "Row " + i + ": FirstAddressLine contains invalid special characters. Please provide a valid First Address Line";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //SecondAddressLine is freeform text and will allow up to 150 alphanumeric and allowable special characters.
                    if (secondAddressLine.Length > 150)
                    {
                        returnMessage = "Row " + i + ": SecondAddressLine contains more than 150 characters. Please provide a valid Second Address Line";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //SecondAddressLine allowable special characters are: space, dash, underscore, right and left parentheses, period, apostrophe (O’Reily), ampersand and accented characters.
                    string secondAddressLinePattern = @"^([À-ÿ\w\s-()\*\.\&\'\’_\,\:\,\°\#\\\/]+)$";
                    if (!string.IsNullOrEmpty(secondAddressLine) && !Regex.IsMatch(secondAddressLine, secondAddressLinePattern, RegexOptions.IgnoreCase))
                    {
                        returnMessage = "Row " + i + ": SecondAddressLine contains invalid special characters. Please provide a valid Second Address Line";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //CityName is freeform text and will allow up to 40 alphanumeric and allowable special characters.
                    if (cityName.Length > 40)
                    {
                        returnMessage = "Row " + i + ": CityName contains more than 40 characters. Please provide a valid City Name";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //CityName allowable special characters are: space, dash, underscore, right and left parentheses, period, apostrophe (O’Reily), ampersand and accented characters.
                    string cityNamePattern = @"^[À-ÿ\w\s-()\.\&\'\’_]+$";
                    if (!Regex.IsMatch(cityName, cityNamePattern, RegexOptions.IgnoreCase))
                    {
                        returnMessage = "Row " + i + ": CityName contains invalid special characters. Please provide a valid City Name";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //PostalCode is freeform text and will allow up to 30 alphanumeric and allowable special characters.
                    if (postalCode.Length > 30)
                    {
                        returnMessage = "Row " + i + ": CityName contains more than 30 characters. Please provide a valid Postal Code";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //PostalCode allowable special characters are: space, dash, underscore, right and left parentheses, period, apostrophe (O’Reily), ampersand and accented characters.
                    string postalCodePattern = @"^[À-ÿ\w\s-()\.\&\'\’_]+$";
                    if (!Regex.IsMatch(postalCode, postalCodePattern, RegexOptions.IgnoreCase))
                    {
                        returnMessage = "Row " + i + ": CityName contains invalid special characters. Please provide a valid Postal Code";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //CountryCode must contain any one value from the CountryCode column of the Country table
                    CountryRepository countryRepository = new CountryRepository();
                    Country           country           = countryRepository.GetCountry(countryCode);
                    if (country == null)
                    {
                        returnMessage = "Row " + i + ": CountryCode " + countryCode + " is invalid. Please provide a valid Country Code";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //Where the CountryCode value in the row exists in the StateProvince table then the StateProvinceName column
                    //in the data import file must contain a StateProvinceCode value for the relevant CountryCode.
                    StateProvinceRepository stateProvinceRepository = new StateProvinceRepository();
                    List <StateProvince>    stateProvinces          = stateProvinceRepository.GetStateProvincesByCountryCode(countryCode);
                    StateProvince           stateProvince           = stateProvinceRepository.GetStateProvinceByCountry(countryCode, stateProvinceName);
                    if ((stateProvinces.Count == 0 && !string.IsNullOrEmpty(stateProvinceName)) || (stateProvinces.Count > 0 && stateProvince == null))
                    {
                        returnMessage = "Row " + i + ": StateProvinceName " + stateProvinceName + " is invalid. Please provide a valid State/Province Code";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //LatitudeDecimal must be numerical
                    float validLatitudeDecimal;
                    if (!float.TryParse(latitudeDecimal, out validLatitudeDecimal))
                    {
                        returnMessage = "Row " + i + ": Latitude must be numerical. Please provide a valid Latitude";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //LatitudeDecimal positive and negative numerical values of up to two places prior to the decimal and seven places following the decimal
                    //E.g -999.9999999 and 999.9999999
                    string latitudeDecimalPattern = @"^[-+]?(\d{1,3}\.\d{1,7}|\d{1,3})?$";
                    if (!Regex.IsMatch(latitudeDecimal, latitudeDecimalPattern, RegexOptions.IgnoreCase))
                    {
                        returnMessage = "Row " + i + ": Latitude must be between -999.9999999 and 999.9999999. Please provide a valid Latitude";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //LongitudeDecimal must be numerical
                    float validLongitudeDecimal;
                    if (!float.TryParse(longitudeDecimal, out validLongitudeDecimal))
                    {
                        returnMessage = "Row " + i + ": Longitude must be numerical. Please provide a valid Latitude";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //LongitudeDecimal positive and negative numerical values of up to three places prior to the decimal and seven places following the decimal
                    //E.g -999.9999999 and 999.9999999
                    string longitudeDecimalPattern = @"^[-+]?(\d{1,3}\.\d{1,7}|\d{1,3})?$";
                    if (!Regex.IsMatch(longitudeDecimal, longitudeDecimalPattern, RegexOptions.IgnoreCase))
                    {
                        returnMessage = "Row " + i + ": Longitude must be between -999.9999999 and 999.9999999. Please provide a valid Longitude";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //Ranking may be empty or NULL or contain an integer from 1 to 9 inclusive
                    string rankingPattern = @"\d{1,9}?";
                    if (ranking.ToLower() != "null" && !string.IsNullOrEmpty(ranking) && !Regex.IsMatch(ranking, rankingPattern, RegexOptions.IgnoreCase))
                    {
                        returnMessage = "Row " + i + ": Ranking is from 1 to 9. Please provide a valid Rank";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    int  validRanking;
                    bool isRankingNumerical = Int32.TryParse(ranking, out validRanking);
                    if (isRankingNumerical && ranking.ToLower() != "null" && !string.IsNullOrEmpty(ranking))
                    {
                        XmlElement xmlRanking = doc.CreateElement("Ranking");
                        xmlRanking.InnerText = ranking;
                        xmlClientTopUnitLocationItem.AppendChild(xmlRanking);
                    }

                    //Attach the XML Element for an item to the Document
                    root.AppendChild(xmlClientTopUnitLocationItem);
                }
            }
            if (i == 0)
            {
                returnMessage = "There is no data in the file";
                returnMessages.Add(returnMessage);
            }

            ClientTopUnitImportStep2VM preImportCheckResult = new ClientTopUnitImportStep2VM();

            preImportCheckResult.ReturnMessages = returnMessages;

            if (returnMessages.Count != 0)
            {
                preImportCheckResult.IsValidData = false;
            }
            else
            {
                //DB Check
                string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

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

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

                preImportCheckResult.FileBytes = array;

                preImportCheckResult.IsValidData = true;
            }

            return(preImportCheckResult);
        }
        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("BookingChannels");

            doc.AppendChild(root);

            string returnMessage;

            int i = 0;

            //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 gdsCode = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[0]));                                 //Required
                    string bookingChannelTypeDescription       = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[1]));     //Required
                    string productChannelTypeDescription       = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[2]));     //Required
                    string bookingPseudoCityOrOfficeId         = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[3]));
                    string ticketingPseudoCityOrOfficeId       = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[4]));
                    string desktopUsedTypeDescription          = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[5]));     //Required when Booking Channel = Offline
                    string additionalBookingCommentDescription = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[6]));
                    string languageCode = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[7]));

                    //Build the XML Element for items

                    XmlElement xmlBookingChannelItem = doc.CreateElement("BookingChannelItem");

                    //Validate data

                    /* GDS Code */

                    //Required
                    if (string.IsNullOrEmpty(gdsCode) == true)
                    {
                        returnMessage = "Row " + i + ": GDSCode is missing. Please provide a GDS Code";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }
                    else
                    {
                        //GDSCode must contain any one value from the GDSCode column of the GDS table
                        GDSRepository gdsRepository = new GDSRepository();
                        GDS           gds           = gdsRepository.GetGDS(gdsCode);
                        if (gds == null)
                        {
                            returnMessage = "Row " + i + ": GDSCode " + gdsCode + " is invalid. Please provide a valid GDS Code";
                            if (!returnMessages.Contains(returnMessage))
                            {
                                returnMessages.Add(returnMessage);
                            }
                        }
                    }

                    XmlElement xmlGDSCode = doc.CreateElement("GDSCode");
                    xmlGDSCode.InnerText = gdsCode;
                    xmlBookingChannelItem.AppendChild(xmlGDSCode);

                    /* Booking Channel Type */
                    string bookingChannelTypeId = string.Empty;
                    BookingChannelTypeRepository bookingChannelTypeRepository = new BookingChannelTypeRepository();
                    BookingChannelType           bookingChannelType           = new BookingChannelType();

                    //Required
                    if (string.IsNullOrEmpty(bookingChannelTypeDescription) == true)
                    {
                        returnMessage = "Row " + i + ": Booking Channel  is missing. Please provide a Booking Channel";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }
                    else
                    {
                        //BookingChannelTypeDescription must contain any one value from the BookingChannelTypeDescription column of the BookingChannelType table
                        bookingChannelType = bookingChannelTypeRepository.GetBookingChannelTypeByDescription(bookingChannelTypeDescription);

                        if (bookingChannelType == null)
                        {
                            returnMessage = "Row " + i + ": BookingChannelTypeDescription " + bookingChannelTypeDescription + " is invalid. Please provide a valid BookingChannelType Code";
                            if (!returnMessages.Contains(returnMessage))
                            {
                                returnMessages.Add(returnMessage);
                            }
                        }
                        else
                        {
                            bookingChannelTypeId = bookingChannelType.BookingChannelTypeId.ToString();
                        }
                    }

                    XmlElement xmlBookingChannelTypeId = doc.CreateElement("BookingChannelTypeId");
                    xmlBookingChannelTypeId.InnerText = bookingChannelTypeId;
                    xmlBookingChannelItem.AppendChild(xmlBookingChannelTypeId);

                    /* Product Channel Type */
                    string productChannelTypeId = string.Empty;

                    ProductChannelTypeRepository productChannelTypeRepository = new ProductChannelTypeRepository();
                    ProductChannelType           productChannelType           = new ProductChannelType();

                    //Required
                    if (string.IsNullOrEmpty(productChannelTypeDescription) == true)
                    {
                        returnMessage = "Row " + i + ": Product Channel is missing. Please provide a Product Channel";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }
                    else
                    {
                        //ProductChannelTypeDescription must contain any one value from the ProductChannelTypeDescription column of the ProductChannelType table
                        productChannelType = productChannelTypeRepository.GetProductChannelTypeByDescription(productChannelTypeDescription);
                        if (productChannelType == null)
                        {
                            returnMessage = "Row " + i + ": ProductChannelTypeDescription " + productChannelTypeDescription + " is invalid. Please provide a valid ProductChannelType Code";
                            if (!returnMessages.Contains(returnMessage))
                            {
                                returnMessages.Add(returnMessage);
                            }
                        }
                        else
                        {
                            productChannelTypeId = productChannelType.ProductChannelTypeId.ToString();
                        }
                    }

                    XmlElement xmlProductChannelTypeId = doc.CreateElement("ProductChannelTypeId");
                    xmlProductChannelTypeId.InnerText = productChannelTypeId;
                    xmlBookingChannelItem.AppendChild(xmlProductChannelTypeId);

                    //ProductChannelTypeId and BookingChannelTypeID must be present in the ProductChannelType table
                    if (bookingChannelType != null && bookingChannelType.BookingChannelTypeId > 0 && productChannelType != null && productChannelType.ProductChannelTypeId > 0)
                    {
                        ProductChannelType productChannelBookingChannelType = productChannelTypeRepository.GetProductChannelTypeBookingChannelType(bookingChannelType.BookingChannelTypeId, productChannelType.ProductChannelTypeId);
                        if (productChannelBookingChannelType == null)
                        {
                            returnMessage = "Row " + i + ": Product Channel and Booking Channel combination is invalid. Please provide a valid combination";
                            if (!returnMessages.Contains(returnMessage))
                            {
                                returnMessages.Add(returnMessage);
                            }
                        }
                    }

                    /* DesktopUsedTypeDescription */
                    string desktopUsedTypeId = string.Empty;

                    //Required if BookingChannelTypeDescription is Offline
                    if (string.IsNullOrEmpty(desktopUsedTypeDescription) == true && bookingChannelTypeDescription.ToLower() == "offline")
                    {
                        returnMessage = "Row " + i + ": Desktop Used is required when Booking Channel is Offline. Please provide a valid Desktop Used or change Booking Channel";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }
                    else if (!string.IsNullOrEmpty(desktopUsedTypeDescription))
                    {
                        //DesktopUsed must contain any one value from the DesktopUsedTypeDescription column of the DesktopUsedType table
                        DesktopUsedTypeRepository desktopUsedTypeRepository = new DesktopUsedTypeRepository();
                        DesktopUsedType           desktopUsedType           = desktopUsedTypeRepository.GetDesktopUsedTypeByDescription(desktopUsedTypeDescription);
                        if (desktopUsedType == null)
                        {
                            returnMessage = "Row " + i + ": Desktop Used  " + desktopUsedTypeDescription + " is invalid. Please provide a valid Desktop Used";
                            if (!returnMessages.Contains(returnMessage))
                            {
                                returnMessages.Add(returnMessage);
                            }
                        }
                        else
                        {
                            desktopUsedTypeId = desktopUsedType.DesktopUsedTypeId.ToString();
                        }
                    }

                    XmlElement xmlDesktopUsedTypeId = doc.CreateElement("DesktopUsedTypeId");
                    xmlDesktopUsedTypeId.InnerText = desktopUsedTypeId;
                    xmlBookingChannelItem.AppendChild(xmlDesktopUsedTypeId);

                    /* BookingPseudoCityOrOfficeId  */

                    int validBookingPseudoCityOrOfficeIdCount = db.ValidPseudoCityOrOfficeIds.Where(x => x.PseudoCityOrOfficeId == bookingPseudoCityOrOfficeId).Count();
                    if (!string.IsNullOrEmpty(bookingPseudoCityOrOfficeId) && validBookingPseudoCityOrOfficeIdCount == 0)
                    {
                        returnMessage = "Row " + i + ": BookingPseudoCityOrOfficeId " + bookingPseudoCityOrOfficeId + " is invalid. Please provide a valid BookingPseudoCityOrOfficeId";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    /* Trim if is not null */

                    if (!string.IsNullOrEmpty(bookingPseudoCityOrOfficeId))
                    {
                        bookingPseudoCityOrOfficeId = bookingPseudoCityOrOfficeId.Trim();
                    }

                    XmlElement xmlBookingPseudoCityOrOfficeId = doc.CreateElement("BookingPseudoCityOrOfficeId");
                    xmlBookingPseudoCityOrOfficeId.InnerText = bookingPseudoCityOrOfficeId;
                    xmlBookingChannelItem.AppendChild(xmlBookingPseudoCityOrOfficeId);

                    /* TicketingPseudoCityOrOfficeId   */

                    int validTicketingPseudoCityOrOfficeIdCount = db.ValidPseudoCityOrOfficeIds.Where(x => x.PseudoCityOrOfficeId == ticketingPseudoCityOrOfficeId).Count();
                    if (!string.IsNullOrEmpty(ticketingPseudoCityOrOfficeId) && validTicketingPseudoCityOrOfficeIdCount == 0)
                    {
                        returnMessage = "Row " + i + ": TicketingPseudoCityOrOfficeId " + ticketingPseudoCityOrOfficeId + " is invalid. Please provide a valid TicketingPseudoCityOrOfficeId";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    /* Trim if is not null */

                    if (!string.IsNullOrEmpty(ticketingPseudoCityOrOfficeId))
                    {
                        ticketingPseudoCityOrOfficeId = ticketingPseudoCityOrOfficeId.Trim();
                    }

                    XmlElement xmlTicketingPseudoCityOrOfficeId = doc.CreateElement("TicketingPseudoCityOrOfficeId");
                    xmlTicketingPseudoCityOrOfficeId.InnerText = ticketingPseudoCityOrOfficeId;
                    xmlBookingChannelItem.AppendChild(xmlTicketingPseudoCityOrOfficeId);

                    /* AdditionalBookingComment  */

                    if (!string.IsNullOrEmpty(additionalBookingCommentDescription))
                    {
                        //AdditionalBookingComment is freeform text and will allow up to 1500 alphanumeric and allowable special characters.
                        if (additionalBookingCommentDescription.Length > 1500)
                        {
                            returnMessage = "Row " + i + ": AdditionalBookingComment contains more than 1500 characters. Please provide a valid AdditionalBookingComment";
                            if (!returnMessages.Contains(returnMessage))
                            {
                                returnMessages.Add(returnMessage);
                            }
                        }

                        //Allowable special characters are: space, dash, underscore, right and left parentheses, period, apostrophe (O’Reily), ampersand and accented characters.
                        string additionalBookingCommentPattern = @"^[À-ÿ\w\s\-\(\)\.\&\'\’_]+$";
                        if (!Regex.IsMatch(additionalBookingCommentDescription, additionalBookingCommentPattern, RegexOptions.IgnoreCase))
                        {
                            returnMessage = "Row " + i + ": AdditionalBookingComment contains invalid special characters. Please provide a valid AdditionalBookingComment";
                            if (!returnMessages.Contains(returnMessage))
                            {
                                returnMessages.Add(returnMessage);
                            }
                        }
                    }

                    XmlElement xmlAdditionalBookingCommentDescription = doc.CreateElement("AdditionalBookingCommentDescription");
                    xmlAdditionalBookingCommentDescription.InnerText = additionalBookingCommentDescription;
                    xmlBookingChannelItem.AppendChild(xmlAdditionalBookingCommentDescription);

                    /* Language Code */

                    //Where the AdditionalBookingComment value exists, then the LanguageCode column must contain a LanguageCode value,
                    if (!string.IsNullOrEmpty(additionalBookingCommentDescription) && (languageCode == null || string.IsNullOrEmpty(languageCode)))
                    {
                        returnMessage = "Row " + i + ": AdditionalBookingComment provided, LanguageCode is mandatory. Please provide a valid LanguageCode";
                        if (!returnMessages.Contains(returnMessage))
                        {
                            returnMessages.Add(returnMessage);
                        }
                    }

                    //LanguageCode must contain any one value from the LanguageCode column of the Language table
                    if (!string.IsNullOrEmpty(languageCode))
                    {
                        LanguageRepository languageRepository = new LanguageRepository();
                        Language           language           = languageRepository.GetLanguage(languageCode);
                        if (language == null)
                        {
                            returnMessage = "Row " + i + ": LanguageCode " + languageCode + " is invalid. Please provide a valid Language Code";
                            if (!returnMessages.Contains(returnMessage))
                            {
                                returnMessages.Add(returnMessage);
                            }
                        }
                    }

                    XmlElement xmlLanguageCode = doc.CreateElement("LanguageCode");
                    xmlLanguageCode.InnerText = languageCode;
                    xmlBookingChannelItem.AppendChild(xmlLanguageCode);

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

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