Ejemplo n.º 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[] { });
            }
Ejemplo n.º 2
0
            private async Task CreateCommentAsync(Comment comment, CancellationToken cancellationToken)
            {
                await _context.Comment.AddAsync(comment, cancellationToken)
                .ConfigureAwait(false);

                await _context.SaveChangesAsync(cancellationToken)
                .ConfigureAwait(false);
            }
            private async Task CreateCategoryAsync(Category category, CancellationToken cancellationToken)
            {
                await _context.Category.AddAsync(category, cancellationToken)
                .ConfigureAwait(false);

                await _context.SaveChangesAsync(cancellationToken)
                .ConfigureAwait(false);
            }
Ejemplo n.º 4
0
            private async Task CreatePostAsync(Post post, CancellationToken cancellationToken)
            {
                await _context.Post.AddAsync(post, cancellationToken)
                .ConfigureAwait(false);

                await _context.SaveChangesAsync(cancellationToken)
                .ConfigureAwait(false);
            }
            private async Task CreatePostRateAsync(Domain.Primary.Entities.PostRate postRate, CancellationToken cancellationToken)
            {
                await _context.PostRate.AddAsync(postRate, cancellationToken)
                .ConfigureAwait(false);

                await _context.SaveChangesAsync(cancellationToken)
                .ConfigureAwait(false);
            }
Ejemplo n.º 6
0
            public async Task <Unit> Handle(UpdateCategoryCommand request, CancellationToken cancellationToken)
            {
                Category category = await _context.Category.FindAsync(request.CategoryId)
                                    .ConfigureAwait(false)
                                    ?? throw new NotFoundException(nameof(Category), request.CategoryId);

                UpdateCategoryProperties(category, request);
                await _context.SaveChangesAsync(cancellationToken)
                .ConfigureAwait(false);

                return(Unit.Value);
            }
Ejemplo n.º 7
0
            public async Task <Unit> Handle(DeleteCommentCommand request, CancellationToken cancellationToken)
            {
                Comment comment = await _context.Comment
                                  .Include(c => c.CommentRates)
                                  .SingleOrDefaultAsync(c => c.CommentId == request.CommentId, cancellationToken)
                                  .ConfigureAwait(false)
                                  ?? throw new NotFoundException(nameof(Comment), request.CommentId);

                MarkCommentForRemove(comment);
                await _context.SaveChangesAsync(cancellationToken)
                .ConfigureAwait(false);

                return(Unit.Value);
            }
Ejemplo n.º 8
0
            public async Task <Unit> Handle(DeletePostCommand request, CancellationToken cancellationToken)
            {
                Post post = await _context.Post
                            .Include(p => p.Comments)
                            .SingleOrDefaultAsync(p => p.PostId == request.PostId, cancellationToken)
                            .ConfigureAwait(false)
                            ?? throw new NotFoundException(nameof(Post), request.PostId);

                MarkPostForRemove(post);
                await _context.SaveChangesAsync(cancellationToken)
                .ConfigureAwait(false);

                return(Unit.Value);
            }
Ejemplo n.º 9
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);
            }
Ejemplo n.º 10
0
            public async Task <Unit> Handle(DeleteCategoryOfPostCommand request, CancellationToken cancellationToken)
            {
                Post post = await _context.Post
                            .Include(p => p.Categories)
                            .SingleOrDefaultAsync(p => p.PostId == request.PostId, cancellationToken)
                            .ConfigureAwait(false)
                            ?? throw new NotFoundException(nameof(Post), request.PostId);

                Category category = await _context.Category
                                    .FindAsync(request.CategoryId)
                                    .ConfigureAwait(false)
                                    ?? throw new NotFoundException(nameof(Category), request.CategoryId);

                post.Categories.Remove(category);
                await _context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

                return(Unit.Value);
            }