public string AddComment(Video video, Comment comment) { //List<Comment> comments = GetComments(video); //int commentID = comments.Count() + 1; string query = "INSERT INTO SE_REACTIE (REACTIEID,VIDEOID,TEKST,GEBRUIKERSNAAM,DATUM,LIKES) VALUES (:commentID,:videoID,:commentText,:commentPoster,:commentPostedDate,'"+0+"')"; // Located lower than usual, because GetComments(video) would close the connection. if (connection.State != ConnectionState.Open) { connection.Open(); } OracleCommand command = new OracleCommand(query, connection); command.CommandType = CommandType.Text; command.Parameters.Add("commentID", comment.CommentID); command.Parameters.Add("videoID", video.VideoID); command.Parameters.Add("commentText", comment.Text); command.Parameters.Add("commentPoster", comment.Poster.Username); command.Parameters.Add("commentPostedDate", comment.PostedDate); try { command.ExecuteNonQuery(); } catch (Exception ex) { return ex.ToString(); // Catch if the command was not succesfully executed. } connection.Close(); return "Reactie succesvol toegevoegd"; }
public Comment(int commentID,Video video, string text, User poster, Comment commentOn) { this.CommentID = commentID; this.Video = video; this.Text = text; this.Poster = poster; // If possible, change this to date/time on the server. this.PostedDate = DateTime.Now.ToShortDateString(); this.Likes = 0; this.CommentOn = commentOn; }
protected void BtnAddComment_Click(object sender, EventArgs e) { if (tbAddComment.Text != string.Empty) { int highestCommentID = 0; foreach (Comment c in Comments) { if (c.CommentID >= highestCommentID) { highestCommentID = c.CommentID +1; } } Comment newcomment = new Comment(highestCommentID,CurrentVideo, tbAddComment.Text, CurrentUser); lblErrorMessages.Text= databaseManager.AddComment(CurrentVideo, newcomment); AddComments(); } }
public PlainComment(Comment comment) { this.Text = comment.Text; this.Poster = comment.Poster.Username; this.OriginalComment = comment; }
public List<Comment> GetComments(Video video) { List<Comment> comments = new List<Comment>(); Comment comment; if (connection.State != ConnectionState.Open) { connection.Open(); } string query = "SELECT * FROM SE_REACTIE WHERE VIDEOID=:videoID"; OracleCommand command = new OracleCommand(query, connection); command.CommandType = CommandType.Text; command.Parameters.Add("videoID", video.VideoID); OracleDataReader dataReader; int commentID = 0; string text = string.Empty; string username = string.Empty; User user; int commentOnInt = 0; Comment commentOn; try { dataReader = command.ExecuteReader(); while (dataReader.Read()) { commentID = Convert.ToInt32(dataReader["REACTIEID"]); text = Convert.ToString(dataReader["TEKST"]); username = Convert.ToString(dataReader["GEBRUIKERSNAAM"]); user = GetUser(username); // GetUser(username) will close the connection, so open it again. if (connection.State != ConnectionState.Open) { connection.Open(); } try { commentOnInt = Convert.ToInt32(dataReader["REACTIEOP"]); commentOn = GetComment(commentOnInt); comment = new Comment(commentID, video, text, user, commentOn); } catch { comment = new Comment(commentID, video, text, user); } comments.Add(comment); } } catch { // Catch if reading from the database doesn't work } connection.Close(); return comments; }
public Comment GetComment(int commentID) { Comment comment = new Comment(0, null, string.Empty, null); if (connection.State != ConnectionState.Open) { connection.Open(); } string query = "SELECT * FROM SE_REACTIE WHERE REACTIEID=commentID"; OracleCommand command = new OracleCommand(query, connection); command.CommandType = CommandType.Text; command.Parameters.Add("commentID", commentID); OracleDataReader dataReader; int commentIDInt = 0; int videoID; string text = string.Empty; string username = string.Empty; User user; int commentOnInt = 0; Comment commentOn; try { dataReader = command.ExecuteReader(); while (dataReader.Read()) { commentIDInt = Convert.ToInt32(dataReader["REACTIEID"]); text = Convert.ToString(dataReader["TEKST"]); videoID = Convert.ToInt32(dataReader["VIDEOID"]); username = Convert.ToString(dataReader["GEBRUIKERSNAAM"]); user = GetUser(username); commentOnInt = Convert.ToInt32(dataReader["REACTIEOP"]); Video video = GetVideo(videoID); if (commentOnInt != 0) { commentOn = GetComment(commentOnInt); comment = new Comment(commentID, video, text, user, commentOn); } else { comment = new Comment(commentID, video, text, user); } } } catch { // Catch if reading from the database doesn't work } connection.Close(); return comment; }