예제 #1
0
            public async Task <Unit> Handle(RemoveRateOfCommentCommand request, CancellationToken cancellationToken)
            {
                Domain.Primary.Entities.CommentRate commentRate = await _context.CommentRate
                                                                  .Where(cr => cr.CommentId == request.CommentId && cr.UserId == request.UserId)
                                                                  .SingleOrDefaultAsync(cancellationToken)
                                                                  .ConfigureAwait(false);

                if (commentRate != null)
                {
                    _context.CommentRate.Remove(commentRate);
                    await _context
                    .SaveChangesAsync(cancellationToken)
                    .ConfigureAwait(false);

                    return(Unit.Value);
                }

                await _userStorage.ThrowIfDoesNotExistAsync(request.UserId)
                .ConfigureAwait(false);

                await _context.Comment.ThrowIfDoesNotExistAsync(request.CommentId)
                .ConfigureAwait(false);

                throw new NotFoundException(nameof(Domain.Primary.Entities.CommentRate), new object[] { });
            }
예제 #2
0
            public async Task <Guid> Handle(CreateCommentCommand request, CancellationToken cancellationToken)
            {
                await _userStorage.ThrowIfDoesNotExistAsync(request.UserId)
                .ConfigureAwait(false);

                Comment comment = ConvertToComment(request);

                await CreateCommentAsync(comment, cancellationToken)
                .ConfigureAwait(false);

                return(comment.CommentId);
            }
예제 #3
0
            public async Task <Guid> Handle(CreatePostCommand request, CancellationToken cancellationToken)
            {
                await _userStorage.ThrowIfDoesNotExistAsync(request.UserId)
                .ConfigureAwait(false);

                Post post = ConvertToPost(request);

                await CreatePostAsync(post, cancellationToken)
                .ConfigureAwait(false);

                return(post.PostId);
            }
            public async Task <Guid> Handle(AddRateToPostCommand request, CancellationToken cancellationToken)
            {
                await _userStorage.ThrowIfDoesNotExistAsync(request.UserId)
                .ConfigureAwait(false);

                Domain.Primary.Entities.PostRate postRate = ConvertToPostRate(request);

                await CreatePostRateAsync(postRate, cancellationToken)
                .ConfigureAwait(false);

                return(postRate.PostRateId);
            }
예제 #5
0
            public async Task <Unit> Handle(UpdateCommentCommand request, CancellationToken cancellationToken)
            {
                await _userStorage.ThrowIfDoesNotExistAsync(request.UserId)
                .ConfigureAwait(false);

                Comment comment = await _context.Comment.FindAsync(request.CommentId)
                                  .ConfigureAwait(false)
                                  ?? throw new NotFoundException(nameof(Comment), request.CommentId);

                UpdateCommentProperties(comment, request);
                await _context.SaveChangesAsync(cancellationToken)
                .ConfigureAwait(false);

                return(Unit.Value);
            }
예제 #6
0
            public async Task <IPagedList <PostDto> > Handle(GetPagedListOfPostsMadeByUserQuery request,
                                                             CancellationToken cancellationToken)
            {
                IPagedList <PostDto> posts = await _context.Post
                                             .AsNoTracking()
                                             .Where(p => p.UserId == request.UserId)
                                             .OrderBy(p => p.PostId)
                                             .ProjectTo <PostDto>(_mapper.ConfigurationProvider)
                                             .ProjectToPagedListAsync(request, cancellationToken)
                                             .ConfigureAwait(false);

                if (posts.TotalItemsCount == 0)
                {
                    await _userStorage.ThrowIfDoesNotExistAsync(request.UserId)
                    .ConfigureAwait(false);
                }

                return(posts);
            }
            public async Task <IPagedList <CommentDto> > Handle(GetPagedListOfUserCommentsQuery request,
                                                                CancellationToken cancellationToken)
            {
                IPagedList <CommentDto> comments = await _context.Comment
                                                   .AsNoTracking()
                                                   .Where(c => c.UserId == request.UserId)
                                                   .OrderBy(c => c.CommentId)
                                                   .ProjectTo <CommentDto>(_mapper.ConfigurationProvider)
                                                   .ProjectToPagedListAsync(request, cancellationToken)
                                                   .ConfigureAwait(false);

                if (comments.TotalItemsCount == 0)
                {
                    await _userStorage.ThrowIfDoesNotExistAsync(request.UserId)
                    .ConfigureAwait(false);
                }

                return(comments);
            }