protected void btnDelete_Click(object sender, EventArgs e)
    {
        topic_id = Convert.ToInt32(Request.QueryString["topicID"]);

        qSoc_Topic topic = new qSoc_Topic(topic_id);
        topic.Available = "No";
        topic.MarkAsDelete = 1;
        topic.Update();

        Response.Redirect("topics-list.aspx");
    }
    protected void btnSave_OnClick(object sender, System.EventArgs e)
    {
        int user_id = Convert.ToInt32(Context.Items["UserID"]);

        if (!String.IsNullOrEmpty(Request.QueryString["topicID"]))
        {
            topic_id = Convert.ToInt32(Request.QueryString["topicID"]);
            qSoc_Topic topic = new qSoc_Topic(topic_id);

            topic.Name = txtName.Text;
            topic.URL = txtURL.Text;
            topic.Summary = txtSummary.Text;
            topic.Description = reContent.Content;
            topic.Available = rblAvailable.SelectedValue;
            topic.LastModified = DateTime.Now;
            topic.LastModifiedBy = user_id;
            topic.ImageURL = txtImageURL.Text;
            topic.IconURL = txtIconURL.Text;
            topic.Update();
        }
        else
        {
            qSoc_Topic topic = new qSoc_Topic();
            topic.ScopeID = 1;
            topic.Created = DateTime.Now;
            topic.CreatedBy = user_id;
            topic.LastModified = DateTime.Now;
            topic.LastModifiedBy = user_id;
            topic.Available = "Yes";
            topic.MarkAsDelete = 0;
            topic.Name = txtName.Text;
            topic.URL = txtURL.Text;
            topic.Summary = txtSummary.Text;
            topic.Description = reContent.Content;
            topic.Available = rblAvailable.SelectedValue;
            topic.ImageURL = txtImageURL.Text;
            topic.IconURL = txtIconURL.Text;
            topic.Insert();

            topic_id = topic.TopicID;
        }

        // add keywords
        qPtl_KeywordReference.DeleteKeywordReferencesByContent((int)qSoc_ContentType.Types.Topic, topic_id);
        foreach (ListItem item in cblKeywords.Items)
        {
            if (item.Selected)
            {
                qPtl_KeywordReference keyword = new qPtl_KeywordReference();
                keyword.Available = "Yes";
                keyword.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                keyword.KeywordID = Convert.ToInt32(item.Value);
                keyword.ContentTypeID = (int)qSoc_ContentType.Types.Topic;
                keyword.ReferenceID = topic_id;
                keyword.Created = DateTime.Now;
                keyword.LastModified = DateTime.Now;
                keyword.CreatedBy = Convert.ToInt32(Context.Items["UserID"]);
                keyword.LastModifiedBy = Convert.ToInt32(Context.Items["UserID"]);
                keyword.MarkAsDelete = 0;
                keyword.Insert();
            }
        }

        Response.Redirect("~/manage/site/metadata/topics-list.aspx");
    }