Beispiel #1
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);
            }
        }
        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);
            }
        }
        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);
            }
        }