// 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";
            }
        }
        // Gets all the respective Article web controls and builds them. These web controls will be populated
        // with data, too
        private void GetAndDisplayArticleControls(int id)
        {
            _article = MovieWikiDbHelper.GetWikiArticleById(id);
            if (_article == null) return;
            var articleControls = _article.BuildControls();

            foreach (var row in articleControls)
            {
                pnlArticleContent.Controls.Add(row);
            }

            var titleControl = FindControl("Title") as TextBox;
            titleControl.Enabled = false;
            if (MovieWikiDbHelper.IsUserAdmin((Session[Global.ActiveUserAccount] as UserAccount).Username))
            {
                btnDeleteArticle.Visible = true;
            }
            ToggleControls(pnlArticleContent);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // The previous page sends a query string with the article type chosen by the user
            var articleType = Request.QueryString["articleType"];

            // If somehow it was null, go back
            if (articleType == null)
            {
                Response.Redirect("ChooseArticleToCreate.aspx");
            }

            // Get the parameters in the query string. Right now it's just any of the role sections
            var queryStringParameters = Request.QueryString["parameters"];
            var parametersSplit = queryStringParameters == null
                ? null
                : queryStringParameters.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            // Use an ArticleFactory object to get an Article instance (e.g. MovieArticle, PropArticle, etc.)
            // based on the given articleType and parameters from the querystring
            _article = _articleFactory.GetInstance(articleType, parametersSplit);
            lblArticleTemplateHeader.Text = string.Format("{0} Template", _article.ToString());

            BuildArticleTemplate();
        }