// TODO redirect to newly created article page after create button clicked
        protected void btnCreateArticle_Click(object sender, EventArgs e)
        {
            lblError.Text = string.Empty;  // to clear any error text

            // Get all the content of the dynamically created web controls that
            //  the user filled, as XML
            var xml       = _article.ComposeXml(pnlArticleContent);
            var author    = Session[Global.ActiveUserAccount] as UserAccount;
            var title     = xml.Elements("Title").FirstOrDefault().Value;
            var timestamp = DateTime.Now;

            // Insert the article, and, if successfuly, assign it to the active session and update
            // the WikiArticleEditHistory table, too.
            if (MovieWikiDbHelper.InsertWikiArticle(_article.GetType().Name, title, xml.ToString()))
            {
                // Reassign _article now that all the properties are properly set. This isn't totally
                // necessary, but good so that the old article isn't usable afterward
                _article = MovieWikiDbHelper.GetWikiArticleByTitle(title);
                MovieWikiDbHelper.InsertWikiArticleEditHistory(_article.ArticleId, author.AccountId, timestamp);

                Session[Global.ActiveArticle] = _article;
                Response.Redirect("Default.aspx");
            }
            else
            {
                lblError.Text = "An article with that title already exists";
            }
        }
Пример #2
0
        // If a user edited the article, they can save the changes to the database here
        private void UpdateEdits()
        {
            var xml = _article.ComposeXml(pnlArticleContent);
            // NB editor does not always equal article author (the original author that created the article)
            var editor    = Session[Global.ActiveUserAccount] as UserAccount;
            var timestamp = DateTime.Now;

            if (MovieWikiDbHelper.UpdateWikiArticle(_article.ArticleId, xml.ToString()))
            {
                MovieWikiDbHelper.InsertWikiArticleEditHistory(_article.ArticleId, editor.AccountId, timestamp);
                Session[Global.ActiveArticle] = _article;
            }
            else
            {
                Response.Write("An error occured while updating the article");
            }
        }