Beispiel #1
0
        //      public IEnumerable<Comment> Get_Sub_Comments(string post_id, string comment_id, int take, int skip)
        //      {
        //          var post_comments_collection = dataContext.getConnection().GetCollection<Post_Comment>("Post_Comment");
        //          var filter = Builders<Post_Comment>.Filter.And(
        //Builders<Post_Comment>.Filter.Where(x => x.post_id == ObjectId.Parse(post_id)),
        //Builders<Post_Comment>.Filter.Eq("comments._id", ObjectId.Parse(comment_id)));
        //          var project = Builders<Post_Comment>.Projection.Combine(Builders<Post_Comment>.Projection.Slice("comments", 0, 1), Builders<Post_Comment>.Projection.Slice("comments.sub_comments", skip, take));
        //          var post_Comments = post_comments_collection.Find(filter).Project(project).SingleAsync().Result;
        //          Debug.WriteLine(post_comments_collection.Find(filter).Project(project));
        //          var demo = BsonSerializer.Deserialize<Post_Comment>(post_Comments);
        //          return demo.comments[0].sub_comments;
        //      }
        public List <Comment> Get_Sub_Comments(string post_id, string comment_id, int take, int skip)
        {
            var post_comments_collection = dataContext.getConnection().GetCollection <Post_Comment>("Post_Comment");
            var doc = post_comments_collection.Aggregate().Match(new BsonDocument {
                { "_id", ObjectId.Parse(post_id) }
            })
                      .Unwind("comments")
                      .Match(new BsonDocument {
                { "comments._id", ObjectId.Parse(comment_id) }
            })
                      .Unwind("comments.sub_comments")
                      .Sort(new BsonDocument {
                { "comments.sub_comments.dateCreated", 1 }
            })
                      .Group("{_id: '$_id', 'comments': {'$push': '$comments.sub_comments'}}")
                      .Project("{'comments': { '$slice\' : ['$comments'," + skip + ", " + take + "] }}");

            Debug.WriteLine(doc);
            var            sub_comments = BsonSerializer.Deserialize <Post_Comment>(doc.SingleAsync().Result);
            List <Comment> comments     = sub_comments.comments;

            foreach (Comment c in comments)
            {
                User u = um.GetUser_Detail(c.owner._id);
                c.owner.user_name    = u.first_name + " " + u.last_name;
                c.owner.user_picture = u.profile_img;
            }
            return(comments);
        }
Beispiel #2
0
        public Notification_Record get_notifications(string user_id)
        {
            var notification_collection = dataContext.getConnection().GetCollection <Notification_Record>("Notification");
            var filter = Builders <Notification_Record> .Filter.Eq("_id", ObjectId.Parse(user_id));

            Notification_Record records = notification_collection.Find(filter).SingleOrDefault();

            foreach (Notification n in records.notifications)
            {
                User u = um.GetUser_Detail(n.sender_id);
                n.sender_name = u.first_name + " " + u.last_name;
                n.sender_pic  = u.profile_img;
            }
            return(records);
        }