public async Task <ActionResult> CommentLike(CommentLikeModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Post", new { id = model.PostId }));
            }

            var blogContext = new BlogContext();


            var fieldName = string.Format("Comments.{0}.Likes", model.Index);

            UpdateDefinition <Post> updateDef = Builders <Post> .Update.Inc(fieldName, 1);

            await blogContext.Posts.UpdateOneAsync(x => x.Id == model.PostId, updateDef);

            var tags = await blogContext.Posts.Aggregate()
                       .Project(x => new { _id = x.Id, Tags = x.Tags })
                       .Unwind(x => x.Tags)
                       .Group("{ _id: '$Tags', Count: { $sum: 1 } }")
                       .Limit(10)
                       .ToListAsync();

            // XXX WORK HERE
            // Increment the Likes field for the comment at {model.Index}
            // inside the post {model.PostId}.
            //
            // NOTE: The 2.0.0 driver has a bug in the expression parser and
            // might throw an exception depending on how you solve this problem.
            // This is documented here along with a workaround:
            // https://jira.mongodb.org/browse/CSHARP-1246

            return(RedirectToAction("Post", new { id = model.PostId }));
        }
Example #2
0
        public async Task <ActionResult> CommentLike(CommentLikeModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Post", new { id = model.PostId }));
            }

            var blogContext = new BlogContext();

            // XXX WORK HERE
            // Increment the Likes field for the comment at {model.Index}
            // inside the post {model.PostId}.
            //
            // NOTE: The 2.0.0 driver has a bug in the expression parser and
            // might throw an exception depending on how you solve this problem.
            // This is documented here along with a workaround:
            // https://jira.mongodb.org/browse/CSHARP-1246
            var filter = Builders <Post> .Filter.Eq(x => x.Id, model.PostId);

            var post = await blogContext.Posts.Find(filter).SingleOrDefaultAsync();

            post.Comments[model.Index].Likes++;
            await blogContext.Posts.ReplaceOneAsync(filter, post);

            return(RedirectToAction("Post", new { id = model.PostId }));
        }
        public async Task <ActionResult> CommentLike(CommentLikeModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Post", new { id = model.PostId }));
            }

            var blogContext = new BlogContext();

            var fieldName = $"Comments.{model.Index}.Likes";

            await blogContext.Posts.FindOneAndUpdateAsync(p => p.Id == model.PostId,
                                                          Builders <Post> .Update.Inc(fieldName, 1));

            // XXX WORK HERE
            // Increment the Likes field for the comment at {model.Index}
            // inside the post {model.PostId}.
            //
            // NOTE: The 2.0.0 driver has a bug in the expression parser and
            // might throw an exception depending on how you solve this problem.
            // This is documented here along with a workaround:
            // https://jira.mongodb.org/browse/CSHARP-1246

            return(RedirectToAction("Post", new { id = model.PostId }));
        }
Example #4
0
        public async Task <ActionResult> CommentLike(CommentLikeModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Post", new { id = model.PostId }));
            }

            BlogServices.CommentLike(model.Index, model.PostId);

            return(RedirectToAction("Post", new { id = model.PostId }));
        }
        public async Task <ActionResult> CommentLike(CommentLikeModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Post", new { id = model.PostId }));
            }

            var blogContext = new BlogContext();



            return(RedirectToAction("Post", new { id = model.PostId }));
        }
        public async Task <ActionResult> CommentLike(CommentLikeModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Post", new { id = model.PostId }));
            }

            var blogContext = new BlogContext();

            // XXX WORK HERE
            var fieldName = string.Format("Comments.{0}.Likes", model.Index);

            UpdateDefinition <Post> updateDef = Builders <Post> .Update.Inc(fieldName, 1);

            await blogContext.Posts.UpdateOneAsync(x => x.Id == model.PostId, updateDef);

            return(RedirectToAction("Post", new { id = model.PostId }));
        }
Example #7
0
 public HttpResponseMessage CommentLike(CommentLikeModel objData)
 {
     BlogServices.CommentLike(objData.Index, objData.PostId);
     return(Request.CreateResponse(HttpStatusCode.OK, new { Data = objData.PostId }));
 }