コード例 #1
0
        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));
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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));
        }