示例#1
0
        public async Task <ActionResult <CommentResponse> > Comment(int commentId, [FromQuery] CommentParameters parameters)
        {
            var comment = await commentsRepo.FindCommentByIdAsync(commentId).ConfigureAwait(false);

            if (comment == null)
            {
                return(NotFound(new ErrorResponse($"Comment {commentId} not found")));
            }
            var canUserSeeNotApprovedComments = await CanUserSeeNotApprovedCommentsAsync(UserId, comment.CourseId).ConfigureAwait(false);

            DefaultDictionary <int, int> likesCount;

            if (parameters.WithReplies)
            {
                var replies = await commentsRepo.GetRepliesAsync(commentId).ConfigureAwait(false);

                likesCount = await commentLikesRepo.GetLikesCountsAsync(replies.Append(comment).Select(c => c.Id)).ConfigureAwait(false);

                return(BuildCommentResponse(
                           comment,
                           canUserSeeNotApprovedComments, new DefaultDictionary <int, List <Comment> > {
                    { commentId, replies }
                }, likesCount,
                           addCourseIdAndSlideId: true, addParentCommentId: true, addReplies: true
                           ));
            }

            likesCount = await commentLikesRepo.GetLikesCountsAsync(new [] { commentId }).ConfigureAwait(false);

            return(BuildCommentResponse(
                       comment,
                       canUserSeeNotApprovedComments, new DefaultDictionary <int, List <Comment> >(), likesCount,
                       addCourseIdAndSlideId: true, addParentCommentId: true, addReplies: false
                       ));
        }
示例#2
0
        public async Task <ActionResult <CommentResponse> > Comment(int commentId, [FromQuery] CommentParameters parameters)
        {
            var comment = await commentsRepo.FindCommentByIdAsync(commentId).ConfigureAwait(false);

            if (comment == null)
            {
                return(NotFound(new ErrorResponse($"Comment {commentId} not found")));
            }
            var canUserSeeNotApprovedComments = await CanUserSeeNotApprovedCommentsAsync(UserId, comment.CourseId).ConfigureAwait(false);

            DefaultDictionary <int, int> likesCount;
            var likedByUserCommentsIds = (await commentLikesRepo.GetCommentsLikedByUserAsync(comment.CourseId, comment.SlideId, UserId).ConfigureAwait(false)).ToHashSet();
            var isInstructor           = await courseRolesRepo.HasUserAccessToCourseAsync(User.GetUserId(), comment.CourseId, CourseRoleType.Instructor).ConfigureAwait(false);

            var           canViewAllGroupMembers = false;
            HashSet <int> userAvailableGroupsIds = null;

            if (isInstructor)
            {
                canViewAllGroupMembers = await groupAccessesRepo.CanUserSeeAllCourseGroupsAsync(User.GetUserId(), comment.CourseId).ConfigureAwait(false);

                userAvailableGroupsIds = (await groupAccessesRepo.GetAvailableForUserGroupsAsync(User.GetUserId(), false, true, true).ConfigureAwait(false)).Select(g => g.Id).ToHashSet();
            }

            if (parameters.WithReplies)
            {
                var replies = await commentsRepo.GetRepliesAsync(commentId).ConfigureAwait(false);

                var allComments = replies.Append(comment).ToList();
                likesCount = await commentLikesRepo.GetLikesCountsAsync(replies.Append(comment).Select(c => c.Id)).ConfigureAwait(false);

                var authorsIds     = allComments.Select(c => c.Author.Id).Distinct().ToList();
                var authors2Groups = !isInstructor ? null : await groupMembersRepo.GetUsersGroupsAsync(comment.CourseId, authorsIds, true).ConfigureAwait(false);

                return(BuildCommentResponse(
                           comment,
                           canUserSeeNotApprovedComments, new DefaultDictionary <int, List <Comment> > {
                    { commentId, replies }
                }, likesCount, likedByUserCommentsIds,
                           authors2Groups, userAvailableGroupsIds, canViewAllGroupMembers, addCourseIdAndSlideId: true, addParentCommentId: true, addReplies: true
                           ));
            }

            likesCount = await commentLikesRepo.GetLikesCountsAsync(new[] { commentId }).ConfigureAwait(false);

            var author2Groups = !isInstructor ? null : new Dictionary <string, List <Group> >
            {
                {
                    comment.Author.Id,
                    await groupMembersRepo.GetUserGroupsAsync(comment.CourseId, comment.Author.Id).ConfigureAwait(false)
                }
            };

            return(BuildCommentResponse(
                       comment,
                       canUserSeeNotApprovedComments, new DefaultDictionary <int, List <Comment> >(), likesCount, likedByUserCommentsIds, author2Groups,
                       userAvailableGroupsIds, canViewAllGroupMembers, addCourseIdAndSlideId: true, addParentCommentId: true, addReplies: false
                       ));
        }
示例#3
0
        public IActionResult GetListComment([FromQuery] CommentParameters parameters)
        {
            PagedList <Comment> comments = _repoWrapper.Comment.FindByPodcast(parameters);

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(comments.MetaData));

            return(Ok(comments));
        }
        public PagedList <Comment> FindByPodcast(CommentParameters parameters)
        {
            var comments = FindByCondition(c => c.PodcastId == parameters.PodcastId);

            return(PagedList <Comment> .ToPagedList(comments.OrderBy(c => c.PublicationDate),
                                                    parameters.PageNumber,
                                                    parameters.PageSize));
        }