using Netina.Domain.Entities.Comments; namespace Netina.Core.EntityServices.CommentHandlers; public class ConfirmCommentCommandHandler(IRepositoryWrapper repositoryWrapper) : IRequestHandler { public async Task Handle(ConfirmCommentCommand request, CancellationToken cancellationToken) { var review = await repositoryWrapper.SetRepository().TableNoTracking .FirstOrDefaultAsync(r => r.Id == request.Id, cancellationToken); if (review == null) throw new AppException("Comment not found", ApiResultStatusCode.NotFound); review.ConfirmReview(); var productComment = await repositoryWrapper.SetRepository() .TableNoTracking.FirstOrDefaultAsync(f => f.Id == request.Id, cancellationToken); if (productComment != null) { var product = await repositoryWrapper.SetRepository() .TableNoTracking .FirstOrDefaultAsync(p => p.Id == productComment.ProductId, cancellationToken); if (product == null) throw new AppException("Product not found", ApiResultStatusCode.NotFound); product.AddRate(productComment.Rate); repositoryWrapper.SetRepository().Update(product); await repositoryWrapper.SaveChangesAsync(cancellationToken); } repositoryWrapper.SetRepository().Update(review); await repositoryWrapper.SaveChangesAsync(cancellationToken); return review.Id; } }