Esempio n. 1
0
        public static Collection<Comment> CreateCommentsFromReader(SqlDataReader reader)
        {
            Collection<Comment> commentlist = new Collection<Comment>();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    Comment com = new Comment();

                    com.Id = Convert.ToInt32(reader["Id"]);
                    com.PostId = Convert.ToInt32(reader["PostId"]);
                    com.Text = Convert.ToString(reader["text"]);
                    com.Name = Convert.ToString(reader["name"]);
                    com.Url = Convert.ToString(reader["url"]);
                    com.Approved = Convert.ToBoolean(reader["Approved"]);
                    com.Posted = Convert.ToDateTime(reader["Posted"]);

                    commentlist.Add(com);
                }
            }

            return commentlist;
        }
Esempio n. 2
0
        public void SaveComment(object sender, EventArgs e)
        {
            Comment c = new Comment();

            c.Url = editcomment.URL;
            c.Name = editcomment.Name;
            c.PostId = Post.GetPostIdFromQueryString(Request.QueryString);
            c.Text = editcomment.Text;
            c.Posted = DateTime.Now;

            if (String.IsNullOrEmpty(c.Text))
            {
                return;
            }

            c.Save();

            ////if (chkRememberDetails.Checked)
            ////{

            ////    HttpCookie details = new HttpCookie("userDetails");
            ////    details.Values.Add("Name", c.Name);
            ////    details.Values.Add("URL", c.Url);
            ////    Response.Cookies.Add(details);
            ////}
            ////else
            ////{
            ////    if (Request.Cookies["userDetails"] != null)
            ////    {
            ////        HttpCookie details = new HttpCookie("userDetails");
            ////        details.Values.Add("Name", String.Empty);
            ////        details.Values.Add("URL", String.Empty);
            ////        Response.Cookies.Add(details);
            ////    }
            ////}

            editcomment.ClearValues();

            if (Request.Url.Fragment != "#comments")
            {
                Response.Redirect(Request.Url + "#comments");
            }

            this.GetPosts();
        }
Esempio n. 3
0
        public bool AddCommentToPost(Comment com)
        {
            int rowcount = 0;
            using (SqlConnection connection = this.GetConnection())
            {
                connection.Open();

                SqlCommand sc = new SqlCommand("AddComment", connection);
                sc.CommandType = CommandType.StoredProcedure;

                sc.Parameters.AddWithValue("PostId", com.PostId);
                sc.Parameters.AddWithValue("Name", com.Name);
                sc.Parameters.AddWithValue("URL", com.Url);
                sc.Parameters.AddWithValue("Text", com.Text);
                sc.Parameters.AddWithValue("Posted", com.Posted);

                rowcount = sc.ExecuteNonQuery();
            }

            return rowcount > 0;
        }