Beispiel #1
0
        //Adds a new tag to Tags Table
        private Task <Tags> AddTag(string tagText, params int[] postIds)
        {
            Tags tag = new Tags()
            {
                Tag     = tagText,
                PostIds = postIds
            };
            FilterDefinition <Tags> filter = GetTagTextFilter(tagText);

            bool isEntityPresent = db.Tags.CheckAndCreateEntityBool(tag, filter);

            if (isEntityPresent)
            {
                Task <Tags> task = MongoArrayUtils <Tags> .AddToArray <int>(db.Tags, filter, POST_IDS, postIds);

                return(task);
            }
            return(null);
        }
Beispiel #2
0
        //Add a user's like to a Post
        public Task <Likes> AddLike(int postId, params int[] userIds)
        {
            Likes like = new Likes()
            {
                PostId  = postId,
                UserIds = userIds
            };
            FilterDefinition <Likes> filter = GetPostIdFilter(postId);

            //Checks to see if an instance of Like is available
            bool isEntityPresent = db.Likes.CheckAndCreateEntityBool(like, filter);

            if (isEntityPresent)
            {
                Task <Likes> task = MongoArrayUtils <Likes> .AddToArray <int>(db.Likes, filter, USER_IDS, userIds);

                int likesCount = db.Posts.FirstOrDefault(e => e.PostId == postId).LikesCount;
                postRepo.UpdatePostLikesCount(postId);
                return(task);
            }
            return(null);
        }