Esempio n. 1
0
        public bool RemoveUser(long userID)
        {
            return(m_Locker.Synchronized(userID, () =>
            {
                var deleted = TBL_USER.Remove(userID);
                if (!deleted)
                {
                    return false;
                }

                var posts = TBL_USERPOST.Get(userID) as List <long>;
                if (posts == null)
                {
                    return true;
                }
                TBL_USERPOST.Remove(userID); //todo  Rewrite with table.RemoveReturning()

                foreach (var postID in posts)
                {
                    TBL_POST.Remove(postID);
                }

                return true;
            }));
        }
Esempio n. 2
0
        public bool PutPost(Post post)
        {
            return(m_Locker.Synchronized(post.UserID, () =>
            {
                TBL_POST.Put(post.PostID, post);

                var uposts = TBL_USERPOST.Get(post.UserID) as List <long>;
                if (uposts == null)
                {
                    uposts = new List <long>();
                }
                if (uposts.Any(id => id == post.PostID))
                {
                    return false;
                }

                if (uposts.Count > 25)
                {
                    uposts.RemoveAt(0);
                }
                uposts.Add(post.PostID);
                var pr = TBL_USERPOST.Put(post.UserID, uposts);

                return true;
            }));
        }
Esempio n. 3
0
        public bool RemovePost(long postID)
        {
            var post = TBL_POST.Get(postID) as Post;

            if (post == null)
            {
                return(false);
            }
            return(m_Locker.Synchronized(post.UserID, () =>
            {
                var result = TBL_POST.Remove(postID);
                TBL_USERPOST.Remove(post.UserID);
                return result;
            }));
        }
Esempio n. 4
0
 public IEnumerable <Post> GetUserPosts(long userID, out User user)
 {
     user = TBL_USER.Get(userID) as User;
     if (user == null)
     {
         return(Enumerable.Empty <Post>());
     }
     return(m_Locker.Synchronized(userID, () =>
     {
         var posts = TBL_USERPOST.Get(userID) as List <long>;
         if (posts == null)
         {
             return Enumerable.Empty <Post>();
         }
         return posts.Select(pid => TBL_POST.Get(pid) as Post).Where(p => p != null);
     }));
 }
Esempio n. 5
0
        public bool VotePost(long postID, int count)
        {
            var post = TBL_POST.Get(postID) as Post;

            if (post == null)
            {
                return(false);
            }
            return(m_Locker.Synchronized(post.UserID, () =>
            {
                if (count > 0)
                {
                    post.Up += count;
                }
                else
                {
                    post.Down -= count;
                }
                TBL_USERPOST.Put(post.PostID, post);
                return true;
            }));
        }