public bool InsertComment(ArticleComment comment) { string queryString = "INSERT INTO [MLB].[dbo].[ArticleComment] " + " ([ArticleId],[PosterName],[PosterEmail],[PosterWebSite],[CommentText],[RepyToCommentId]) " + " VALUES (@ArticleId,@PosterName,@PosterEmail,@PosterWebSite,@CommentText,@RepyToCommentId)"; using (SqlConnection connection = new SqlConnection(Base.conn)) { // Create the Command and Parameter objects. SqlCommand command = new SqlCommand(queryString, connection); command.Parameters.AddWithValue("@ArticleId", comment.ArticleId); command.Parameters.AddWithValue("@PosterName", comment.PosterName); command.Parameters.AddWithValue("@PosterEmail", comment.PosterEmail); command.Parameters.AddWithValue("@PosterWebSite", comment.PosterWebSite); command.Parameters.AddWithValue("@CommentText", comment.Text); command.Parameters.AddWithValue("@RepyToCommentId", comment.RepyToCommentId); try { connection.Open(); command.ExecuteNonQuery(); } catch (Exception ex) { DIYError sError = new DIYError(ex); } } return true; }
public bool InsertComment(ArticleComment comment) { string queryString = "INSERT INTO [MLB].[dbo].[ArticleComment] " + " ([ArticleId],[PosterName],[PosterEmail],[PosterWebSite],[CommentText],[RepyToCommentId]) " + " VALUES (@ArticleId,@PosterName,@PosterEmail,@PosterWebSite,@CommentText,@RepyToCommentId)"; using (SqlConnection connection = new SqlConnection(Base.conn)) { // Create the Command and Parameter objects. SqlCommand command = new SqlCommand(queryString, connection); command.Parameters.AddWithValue("@ArticleId", comment.ArticleId); command.Parameters.AddWithValue("@PosterName", comment.PosterName); command.Parameters.AddWithValue("@PosterEmail", comment.PosterEmail); command.Parameters.AddWithValue("@PosterWebSite", comment.PosterWebSite); command.Parameters.AddWithValue("@CommentText", comment.Text); command.Parameters.AddWithValue("@RepyToCommentId", comment.RepyToCommentId); try { connection.Open(); command.ExecuteNonQuery(); } catch (Exception ex) { DIYError sError = new DIYError(ex); } } return(true); }
public ActionResult PostComment(ArticleComment comment) { var data = new object(); ArticleComment ac = new ArticleComment(); if (ac.InsertComment(comment)) { data = new { success = true, obj = comment }; } else { data = new { success = false, message = "Failed to insert new comment." }; return Json(data); } return Json(data); }