/// <summary>
    /// The event handler for the delete button clicks
    /// </summary>
    /// <param name="sender">The button control that was clicked</param>
    /// <param name="e">Any arguments that are associated with the event</param>
    protected void OnDeleteButtonClick(object sender, EventArgs e)
    {
        // Make sure the button clicked was a delete button
        Button btClicked = ((Button)sender);
        if (btClicked.CommandName.CompareTo("Delete") == 0)
        {
            // Now get the id from the command argument and delete the namespace from the database
            string cmdArg = btClicked.CommandArgument;
            int ID = Convert.ToInt32(cmdArg.Substring(4));
            NameSpaces siteNameSpaces = new NameSpaces(_basePage);
            siteNameSpaces.RemoveNameSpaceForSite(_basePage.CurrentSite.SiteID, ID);

            // Remove the row from the table that contains the namespace in question
            TableRow removeRow = (TableRow)FindControl("namespaceitem" + ID);
            if (removeRow != null)
            {
                tblNameSpaces.Rows.Remove(removeRow);
            }
        }
    }
Example #2
0
        public void TestRemoveNameSpaceForSite()
        {
            // Create a new NameSpace object and create a new name space for a test site
            IInputContext context = DnaMockery.CreateDatabaseInputContext();

            // Create the namespace object and call the add namespace method
            NameSpaces testNameSpace = new NameSpaces(context);
            NameSpaceItem newName = AddNameSpaceToSite(1, "category");
            Assert.IsTrue(newName.ID > 0, "NameSpaceId is zero! Failed to create new name space. namespace being added = category");

            // Now add some phrases to the namespace by adding some phrases to an article
            List<string> phrases = new List<string>();
            phrases.Add("funny");
            phrases.Add("sad");
            phrases.Add("random");
            phrases.Add("practical");
            
            using (IDnaDataReader reader = context.CreateDnaDataReader("addkeyphrasestoarticle"))
            {
                // Add the phrases
                string keyPhrases = "";
                foreach (string phrase in phrases)
                {
                    keyPhrases += phrase + "|";
                }
                keyPhrases = keyPhrases.TrimEnd('|');
                reader.AddParameter("h2g2id", 5176);
                reader.AddParameter("keywords", keyPhrases);
                reader.AddParameter("namespaces", "category|category|category|category");
                reader.Execute();
            }

            // Now get all the phrases for a given namespace
            List<string> namespacePhrases = GetPhrasesForNameSpace(1, newName.ID, testNameSpace);
            Assert.IsTrue(namespacePhrases.Count == 4, "Get phrases for namespace failed to find all phrases");

            // now compare the phrases with the known values.
            for (int i = 0; i < namespacePhrases.Count; i++)
            {
                // Check to make sure that we have all the same items in both lists
                Assert.IsTrue(phrases.Exists(delegate(string match) { return match == namespacePhrases[i]; }), "Failed to find known phrase in the found phrases. Phrase = " + namespacePhrases[i]);
            }

            // now remove the namespace and check to make sure that the phrases are removed form the article
            using (IDnaDataReader reader3 = context.CreateDnaDataReader("deletenamespaceandassociatedlinks"))
            {
                testNameSpace.RemoveNameSpaceForSite(1, newName.ID);

                // Now get all the phrases for the namespace we removed.
                NameSpaces testNameSpace2 = new NameSpaces(context);
                namespacePhrases = GetPhrasesForNameSpace(1, newName.ID, testNameSpace2);
                Assert.IsTrue(namespacePhrases.Count == 0, "The number of phrases returned from a remove namespace should be zero!");
            }
        }