// 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";
            }
        }
        protected void btnsearchbtn_Click(object sender, EventArgs e)
        {
            var searchResultUrl = MovieWikiDbHelper.GetWikiArticleUrlBySearch(searchInput.Text);

            if (searchResultUrl != null)
            {
                Response.Redirect(searchResultUrl);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal();", true);
                upModal.Update();
            }
        }
        // uses helper classes to check if user exist in database
        // redirects if user exist to home page or displays erro message
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            var username       = txtUsername.Text;
            var hashedPassword = PasswordHelper.GetHashedPassword(txtPassword.Text);
            var userAccount    = MovieWikiDbHelper.GetUserAccount(username, hashedPassword);

            if (userAccount != null)
            {
                Session[Global.ActiveUserAccount] = userAccount;
                Response.Redirect("Default.aspx");
            }
            else
            {
                lblErrorMsg.Text = string.Format(@"Incorrect password for user ""{0}.""", username);
            }
        }
Пример #4
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");
            }
        }
Пример #5
0
        // makes sure user does not exist before adding them to UserAccount class and within database
        protected void btnCreateAccount_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            var username       = txtCreateUsername.Text;
            var hashedPassword = PasswordHelper.GetHashedPassword(txtCreatePassword.Text);

            if (MovieWikiDbHelper.InsertUserAccount(username, hashedPassword))
            {
                Session[Global.ActiveUserAccount] = MovieWikiDbHelper.GetUserAccount(username, hashedPassword);
                Response.Redirect("Default.aspx");
            }
            else
            {
                lblCreateAccountErrorMsg.Text = string.Format(@"The account ""{0}"" already exists", username);
            }
        }
Пример #6
0
        // 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);
        }
Пример #7
0
 // uses helper to remove article from database
 private bool DeleteArticle()
 {
     return(MovieWikiDbHelper.DeleteWikiArticle(_article.ArticleId));
 }