Example #1
0
        public T Update <T>(T entity) where T : class
        {
            var mapper = new Mapper(Session);

            mapper.Update(entity);
            return(entity);
        }
        public UserStreamDTO GetStreamForUser(long id, int LIMIT = 20)
        {
            using (ISession session = _cluster.Connect(_keyspace))
            {
                Cassandra.Mapping.IMapper mapper = new Cassandra.Mapping.Mapper(session);
                session.UserDefinedTypes.Define(new CommentProfile().Definitions);

                var user_stream = mapper.Fetch <UserStream>("where \"User_Id\" = ? LIMIT ? ", id, LIMIT);
                return(_StreamMapper.Map <UserStreamDTO>(user_stream.ToList()));
            }
        }
        public void AddPostToUsersStreams(PostDTO post, List <string> UsersLogins)
        {
            using (ISession session = _cluster.Connect(_keyspace))
            {
                Cassandra.Mapping.IMapper mapper = new Cassandra.Mapping.Mapper(session);

                session.UserDefinedTypes.Define(new CommentProfile().Definitions);

                StreamDTO Stream = _StreamMapper.Map <StreamDTO>(post);

                var Ids = mapper.Fetch <UserDTO>("where \"User_Login\" in (?)", UsersLogins.ToArray()).ToList();
                this.AddPostToUsersStreams(post, Ids.Select(p => p.User_Id).ToList());
            }
        }
        public void AddPostToUsersStreams(PostDTO post, List <long> UsersIds)
        {
            using (ISession session = _cluster.Connect(_keyspace))
            {
                Cassandra.Mapping.IMapper mapper = new Cassandra.Mapping.Mapper(session);

                session.UserDefinedTypes.Define(new CommentProfile().Definitions);
                StreamDTO Stream = _StreamMapper.Map <StreamDTO>(post);
                foreach (var u in UsersIds)
                {
                    Stream.User_Id = u;
                    mapper.Insert(Stream);
                }
            }
        }
        public void UpdateStreamPost(PostDTO post, List <long> UsersIds)
        {
            using (ISession session = _cluster.Connect(_keyspace))
            {
                Cassandra.Mapping.IMapper mapper = new Cassandra.Mapping.Mapper(session);

                session.UserDefinedTypes.Define(new CommentProfile().Definitions);
                foreach (var user in UsersIds)
                {
                    mapper.Update <StreamDTO>("SET \"Likes\" =? ," +
                                              "\"Dislikes\" =?," +
                                              "\"Comments\"=?," +
                                              "\"Modify_Date\" = ?" +
                                              "where \"User_Id\" = ? and \"Post_Id\" = ? ", post.Likes, post.Dislikes, post.Comments, post.Modify_Date, user, post.Post_Id);
                }
            }
        }