Exemple #1
0
        public void UpdateBlogPost(int blogid, BLOGPOST new_post)
        {
            //am i getting here?
            Debug.WriteLine("is this where the problem is?");

            string query = "update blog_post set blogtitle='{0}', blogbody='{1}' where blogid={2} ";

            query = String.Format(query, new_post.GetBPTitle(), new_post.GetBPBody(), blogid);

            Debug.WriteLine("am i getting the information i need?");

            MySqlConnection Connect = new MySqlConnection(ConnectionString);
            MySqlCommand    cmd     = new MySqlCommand(query, Connect);

            try
            {
                Connect.Open();
                cmd.ExecuteNonQuery();
                Debug.WriteLine("Execute query" + query);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Something went wrong in the UpdateBlog Method!");
                Debug.WriteLine(ex.ToString());
            }
            Connect.Close();
        }
        protected void ShowBlogPostInfo(BLOGDB db)
        {
            bool   valid  = true;
            string blogid = Request.QueryString["blogid"];

            if (String.IsNullOrEmpty(blogid))
            {
                valid = false;
            }

            if (valid)
            {
                BLOGPOST blogpost_record = db.FindBlogPost(Int32.Parse(blogid));

                blogpost_title_head.InnerHtml = blogpost_record.GetBPTitle();
                blogpost_title.InnerHtml      = blogpost_record.GetBPTitle();
                blogpost_body.InnerHtml       = blogpost_record.GetBPBody();
            }
            else
            {
                valid = false;
            }
            if (!valid)
            {
                blog.InnerHtml = "There was an error finding that blog post";
            }
        }
Exemple #3
0
        public BLOGPOST FindBlogPost(int id)
        {
            MySqlConnection Connect         = new MySqlConnection(ConnectionString);
            BLOGPOST        result_blogpost = new BLOGPOST();

            try
            {
                string query = "select * from blog_post where blogid = " + id;
                Debug.WriteLine("connection initialized...");

                Connect.Open();

                MySqlCommand    cmd       = new MySqlCommand(query, Connect);
                MySqlDataReader resultset = cmd.ExecuteReader();

                List <BLOGPOST> BlogPosts = new List <BLOGPOST>();

                while (resultset.Read())
                {
                    BLOGPOST currentblogpost = new BLOGPOST();

                    for (int i = 0; i < resultset.FieldCount; i++)
                    {
                        string key   = resultset.GetName(i);
                        string value = resultset.GetString(i);

                        Debug.WriteLine("Attempting to transfer" + key + "data of" + value);


                        switch (key)
                        {
                        case "blogtitle":
                            currentblogpost.SetBPTitle(value);
                            break;

                        case "blogbody":
                            currentblogpost.SetBPBody(value);
                            break;
                        }
                    }
                    BlogPosts.Add(currentblogpost);
                }
                result_blogpost = BlogPosts[0];
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Something went wrong in the find blog method!");
                Debug.WriteLine(ex.ToString());
            }

            Connect.Close();
            Debug.WriteLine("Database Connection Terminated");

            return(result_blogpost);
        }
Exemple #4
0
        protected void AddPost(object sender, EventArgs e)
        {
            BLOGDB db = new BLOGDB();

            BLOGPOST new_post = new BLOGPOST();

            new_post.SetBPTitle(blog_title.Text);
            new_post.SetBPBody(blog_body.Text);

            db.AddBlogPost(new_post);

            Response.Redirect("ListBlogPost.aspx");
        }
Exemple #5
0
        public void AddBlogPost(BLOGPOST new_post)
        {
            string query = 'insert into blog_post (blogtitle, blogbody) values ("{0}","{1}")';

            query = String.Format(query, new_post.GetBPTitle(), new_post.GetBPBody());

            MySqlConnection Connect = new MySqlConnection(ConnectionString);
            MySqlCommand    cmd     = new MySqlCommand(query, Connect);

            try
            {
                Connect.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Something went wrrong in the AddPost Method!");
                Debug.WriteLine(ex.ToString());
            }
            Connect.Close();
        }
Exemple #6
0
        protected void Update_Blog(object sender, EventArgs e)
        {
            BLOGDB db = new BLOGDB();

            bool   valid  = true;
            string blogid = Request.QueryString["blogid"];

            if (String.IsNullOrEmpty(blogid))
            {
                valid = false;
            }

            Debug.WriteLine("i am trying to update the blog with id=" + blogid);

            if (valid)
            {
                BLOGPOST new_blog = new BLOGPOST();

                new_blog.SetBPTitle(blog_title.Text);
                new_blog.SetBPBody(blog_post.Text);
                Debug.WriteLine("the new blog title is " + blog_title.Text + " and the new blog body is " + blog_post.Text);
                try
                {
                    db.UpdateBlogPost(Int32.Parse(blogid), new_blog);
                    Response.Redirect("ShowBlogPost.aspx?blogid=" + blogid);
                }
                catch
                {
                    Debug.WriteLine("now im in the catch, is it working?");
                    valid = false;
                }
            }
            if (!valid)
            {
                Debug.WriteLine("last chance, but we kinda already know we got here");
                blog.InnerHtml = "There was an error updating your blog";
            }
        }
Exemple #7
0
        protected void ShowBlogInfo(BLOGDB db)
        {
            bool   valid  = true;
            string blogid = Request.QueryString["blogid"];

            if (String.IsNullOrEmpty(blogid))
            {
                valid = false;
            }

            if (valid)
            {
                Debug.WriteLine("is this it?");
                BLOGPOST blog_record = db.FindBlogPost(Int32.Parse(blogid));
                update_title.InnerHtml = blog_record.GetBPTitle();
                blog_title.Text        = blog_record.GetBPTitle();
                blog_post.Text         = blog_record.GetBPBody();
            }

            if (!valid)
            {
                blog.InnerHtml = "There was an error updating your blog";
            }
        }