Exemple #1
0
        public void CreatePost(ISession session, string Text, Guid UserID, List <string> Followers)
        {
            Guid postID = Guid.NewGuid();

            TimeUuid UpdTime = TimeUuid.NewId(DateTimeOffset.Now);



            var insertPost = session.Prepare(
                "INSERT INTO Post (PostID, UserID, Text, UpdTime) VALUES(?,?,?, ?)");

            session.Execute(insertPost.Bind(postID, UserID, Text, UpdTime));



            var insertPostFollowers = session.Prepare(
                "INSERT INTO post_followers (PostID, followers) VALUES(?,?)");

            session.Execute(insertPostFollowers.Bind(postID, Followers));

            PostC post = new PostC
            {
                PostID  = postID,
                UserID  = UserID,
                Text    = Text,
                UpdTime = UpdTime
            };

            _stream.SynchronizeStream(session, post);
        }
Exemple #2
0
        public void UpdatePost(ISession session, PostC post)
        {
            TimeUuid UpdTime = TimeUuid.NewId(DateTimeOffset.Now);


            var updatedPost = session.Prepare(
                "Update Post set Text = ?, UpdTime=?  where PostID = ?");

            session.Execute(updatedPost.Bind(post.Text, UpdTime, post.PostID));


            _stream.SynchronizeStream(session, post);
        }
Exemple #3
0
        public void CreateComment(ISession session, PostC post, string Text, Guid UserID)
        {
            TimeUuid UpdTime = TimeUuid.NewId(DateTimeOffset.Now);

            Guid CommentID = new Guid();



            var addComment = session.Prepare(
                "INSERT INTO comments (CommentID, PostID, UserID , Text, UpdTime) VALUES(?,?,?, ?)");

            session.Execute(addComment.Bind(CommentID, post.PostID, UserID, Text, UpdTime));

            var updatedPost = session.Prepare(
                "Update Post set UpdTime=?  where PostID = ?");

            session.Execute(updatedPost.Bind(UpdTime, post.PostID));



            _stream.SynchronizeStream(session, post);
        }
Exemple #4
0
        public void SynchronizeStream(ISession session, PostC post)
        {
            // Get follower list
            var getFollowerList = session.Prepare("Select followers from PostFollowers where PostID = ? ");
            var listFollowers   = session.Execute(getFollowerList.Bind(post.PostID));

            List <string> Followers = new List <string>();

            foreach (var follower in listFollowers)
            {
                Followers = follower.GetValue <List <string> >("followers");
            }

            //Delete post from user stream
            var deletePost = session.Prepare("DELETE FROM UserStream where UserId =? and PostID = ?");

            foreach (var follower in Followers)
            {
                session.Execute(deletePost.Bind(follower, post.PostID));
            }



            var getPosts  = session.Prepare("Select * from Post where PostID = ? ");
            var postsList = session.Execute(getPosts.Bind(post.PostID));

            foreach (var post1 in postsList)
            {
                post.UserID  = post1.GetValue <Guid>("UserID");
                post.UpdTime = post1.GetValue <TimeUuid>("UpdTime");
                post.Text    = post1.GetValue <string>("Text");
            }



            //Get data from comments
            List <CommentC> comments     = new List <CommentC>();
            var             getComments  = session.Prepare("Select comments from Post where PostID = ? ");
            var             listComments = session.Execute(getComments.Bind(post.PostID));

            foreach (var commentRow in listComments)
            {
                CommentC comment = new CommentC()
                {
                    CommentID = commentRow.GetValue <Guid>("CommentID"),
                    UserID    = commentRow.GetValue <Guid>("UserID"),
                    Text      = commentRow.GetValue <string>("Text"),
                    UpdTime   = commentRow.GetValue <TimeUuid>("UpdTime")
                };

                comments.Add(comment);
            }



            //Insert post in user stream
            var insertUserStream =
                session.Prepare("INSERT INTO UserStream (UserID, PostID,  Text, comments, UpdTime) VALUES(?,?,?,?,?,?)");

            foreach (var follower in Followers)
            {
                session.Execute(insertUserStream.Bind(follower, post.PostID, post.Text, comments, post.UpdTime));
            }
        }