public void Add(Comment c) { SqlConnection con = CreateConnection(); try { con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandText = "AddComment"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@recipeID", c.RecipeId); cmd.Parameters.AddWithValue("@userID", c.UserId); cmd.Parameters.AddWithValue("@comment", c.Content); cmd.ExecuteNonQuery(); } catch (SqlException ex) { throw /*ex*/; } finally { if (con != null) { con.Close(); } } }
public void AddComment() { SqlCommentManager scm = new SqlCommentManager(); Comment c = new Comment(); c.UserId = 1; c.Content = "This is good!"; scm.Add(c); }
public Comment MapDbResultToComment(SqlDataReader res) { res.Read(); Comment c = new Comment(); c.Content = res["content"].ToString(); c.Username = res["username"].ToString(); return c; }
private Comment MapResultFromDatabaseToCommentObject(SqlDataReader res) { Comment c = new Comment(); c.Id = (int)res["id"]; c.UserId = (int)res["userId"]; c.Content = res["content"].ToString(); return c; }