public void CreatePost(PostDTOCassandra post, string username) { var session = _cluster.Connect(); var newPost = session.Prepare("INSERT INTO posts (PostID, Username ,Text, Date) VALUES(?,?,?, ?)"); session.Execute(newPost.Bind(post.PostID, username, post.Text, DateTime.Now)); _stream.SynchronizeStream(session, post); }
private void DeletePost(PostDTOCassandra post, ISession session, List <string> list) { var deletePost = session.Prepare("DELETE FROM user_stream where user_id =? and last_updated_at = ?"); foreach (var follower in list) { session.Execute(deletePost.Bind(follower, DateTime.Now)); } }
private void AddTostream(ISession session, PostDTOCassandra post, List <string> list, List <CommentDTOCassandra> comments) { var Stream = session.Prepare("INSERT INTO user_stream (Username, Date , PostID , UserID , Text, Comments) VALUES(?,?,?,?,?,?)"); foreach (var follower in list) { session.Execute(Stream.Bind(follower, DateTime.Now, post.PostID, post.username, post.Text, comments)); } }
public void GetPosts(PostDTOCassandra post, ISession session, List <string> list) { var getPosts = session.Prepare("Select * from posts where Username = ? "); var postsList = session.Execute(getPosts.Bind(post.username)).ToList(); foreach (var post1 in postsList) { post.username = post1.GetValue <string>("Username"); post.Date = post1.GetValue <DateTime>("Date"); post.Text = post1.GetValue <string>("Text"); } }
private void GetFollwers(PostDTOCassandra post, ISession session, List <string> list) { var getFollowerList = session.Prepare("Select followers from Followers where PostID = ? "); var Followers = session.Execute(getFollowerList.Bind(post.PostID)); list = new List <string>(); foreach (var follower in Followers) { list = follower.GetValue <List <string> >("followers"); } }
public void UpdatePost(PostDTOCassandra post, string username) { var session = _cluster.Connect(); var getDate = session.Prepare("Select Date from posts where PostID = ? "); var updatedPost = session.Prepare( "Update posts set Text = ?, Date=? where PostID = ?"); session.Execute(updatedPost.Bind(post.Text, DateTime.Now)); _stream.SynchronizeStream(session, post); }
public void SynchronizeStream(ISession session, PostDTOCassandra post) { session = _cluster.Connect(); List <string> list = new List <string>(); List <CommentDTOCassandra> comments = new List <CommentDTOCassandra>(); GetFollwers(post, session, list); DeletePost(post, session, list); GetPosts(post, session, list); GetComments(comments, post.PostID, session, list); AddTostream(session, post, list, comments); }
public void CreateComment(PostDTOCassandra post, CommentDTOCassandra comment, string username) { var session = _cluster.Connect(); var addComment = session.Prepare( "INSERT INTO comments (PostID, CommentID, Text, UserID) VALUES(?,?,?, ?)"); session.Execute(addComment.Bind(comment.PostID, comment.CommentID, comment.Text, comment.UserID)); var updatedPost = session.Prepare( "Update posts set Date=? where PostID = ?"); session.Execute(updatedPost.Bind(comment.CommentID, comment.PostID)); _stream.SynchronizeStream(session, post); }
public void SyncronizeComment(PostDTOCassandra post, CommentDTOCassandra comment, string username) { _streamData.CreateComment(post, comment, username); }
public void SyncronizeExistingPost(PostDTOCassandra post, string username) { _streamData.UpdatePost(post, username); }
public void SyncronizeNewPost(PostDTOCassandra post, string username) { _streamData.CreatePost(post, username); }
public void SynchronizeStream(PostDTOCassandra post, ISession session) { _stream.SynchronizeStream(session, post); }