Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

757 B
Raw Blame
using Grand.Business.Core.Commands.System.Common;
using Grand.Data;
using Grand.Domain.Catalog;
using Grand.Mediator;

namespace Grand.Business.Messages.Commands.Handlers.Common;

public class ClearMostViewedCommandHandler : IRequestHandler<ClearMostViewedCommand, bool>
{
    private readonly IRepository<Product> _repositoryProduct;

    public ClearMostViewedCommandHandler(IRepository<Product> repositoryProduct)
    {
        _repositoryProduct = repositoryProduct;
    }

    public async Task<bool> Handle(ClearMostViewedCommand request, CancellationToken cancellationToken)
    {
        await _repositoryProduct.UpdateManyAsync(x => x.Viewed != 0,
            UpdateBuilder<Product>.Create().Set(x => x.Viewed, 0));

        return true;
    }
}