public Post AddComment(Comment userComment) { //Add Comment with user id in Comments table context.Comments.Add(userComment); context.SaveChanges(); //Update number of Comments in post table Post post = context.Posts.FirstOrDefault(p => p.Id == userComment.Fk_PostId); post.numOfComments = post.numOfComments + 1; PostsManager postsManager = new PostsManager(context); postsManager.Update(post); return(context.Posts.FirstOrDefault(p => p.Id == userComment.Fk_PostId)); }
public Post deleteLikes(ApplicationUser user, int postId) { //Delete like with user id in Likes table var rlike = context.Likes.Where(l => l.Fk_PostId == postId); Like userLike = rlike.FirstOrDefault(l => l.ApplicationUser.Id == user.Id); context.Likes.Remove(userLike); context.SaveChanges(); //Update number of likes in post table Post post = context.Posts.FirstOrDefault(p => p.Id == postId); post.numOfLikes = post.numOfLikes - 1; PostsManager postsManager = new PostsManager(context); postsManager.Update(post); return(context.Posts.FirstOrDefault(p => p.Id == postId)); }
public Post AddLikes(ApplicationUser user, int postId) { //Add like with user id in Likes table Like userlike = new Like(); userlike.ApplicationUser = user; userlike.Fk_PostId = postId; context.Likes.Add(userlike); context.SaveChanges(); //Update number of likes in post table Post post = context.Posts.FirstOrDefault(p => p.Id == postId); post.numOfLikes = post.numOfLikes + 1; PostsManager postsManager = new PostsManager(context); postsManager.Update(post); return(context.Posts.FirstOrDefault(p => p.Id == postId)); }