public int Like(int postId) { var userId = postService.GetUserIdByPostId(postId); if (!friendService.AreFriends(userId, currentUser.Id) && !(currentUser.Id == userId)) { return(likeService.GetNumberOfLikes(postId)); } if (likeService.CanLike(currentUser.Id, postId) == false) { return(likeService.GetNumberOfLikes(postId)); } likeService.Like(currentUser.Id, postId); return(likeService.GetNumberOfLikes(postId)); }
public IActionResult AddComment(Comment comment) { var userId = postService.GetUserIdByPostId(comment.PostId); if (!friendService.AreFriends(userId, currentUser.Id) && !(currentUser.Id == userId)) { return(AccessDenied()); } comment.UserId = currentUser.Id; commentService.AddComment(comment); return(Ok()); }
public IActionResult ViewProfile(int id) { var user = userService.Get(id); if (user == null) { return(NotFoundView()); } var model = mapper.Map <UserModel>(user); if (currentUser.IsAuthenticated) { model.FriendRequestSent = friendService.FriendRequestSent(currentUser.Id, model.Id); model.Friends = friendService.AreFriends(user, currentUser.Id); } model.CanSeeProfile = user.Privacy == false || model.Friends || model.Id == currentUser.Id || currentUser.CanViewProfile; return(View(model)); }