23 lines
929 B
C#
23 lines
929 B
C#
namespace Netina.Core.EntityServices.ReviewHandlers;
|
|
|
|
public class ConfirmReviewCommandHandler : IRequestHandler<ConfirmReviewCommand , bool>
|
|
{
|
|
private readonly IRepositoryWrapper _repositoryWrapper;
|
|
|
|
public ConfirmReviewCommandHandler(IRepositoryWrapper repositoryWrapper)
|
|
{
|
|
_repositoryWrapper = repositoryWrapper;
|
|
}
|
|
public async Task<bool> Handle(ConfirmReviewCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var review = await _repositoryWrapper.SetRepository<Review>().TableNoTracking
|
|
.FirstOrDefaultAsync(r => r.Id == request.Id, cancellationToken);
|
|
if (review == null)
|
|
throw new AppException("Review not found", ApiResultStatusCode.NotFound);
|
|
review.ConfirmReview();
|
|
|
|
_repositoryWrapper.SetRepository<Review>().Update(review);
|
|
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
return true;
|
|
}
|
|
} |