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.

948 B
Raw Blame
using FluentValidation;
using Grand.Business.Core.Interfaces.Checkout.GiftVouchers;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Infrastructure.Validators;
using Grand.Web.AdminShared.Models.Orders;

namespace Grand.Web.AdminShared.Validators.Orders;

public class GiftVoucherDeleteModelValidator : BaseGrandValidator<GiftVoucherDeleteModel>
{
    public GiftVoucherDeleteModelValidator(
        IEnumerable<IValidatorConsumer<GiftVoucherDeleteModel>> validators,
        IGiftVoucherService giftVoucherService, ITranslationService translationService)
        : base(validators)
    {
        RuleFor(x => x).CustomAsync(async (x, context, _) =>
        {
            var giftVoucher = await giftVoucherService.GetGiftVoucherById(x.Id);
            if (giftVoucher.GiftVoucherUsageHistory.Any())
                context.AddFailure(translationService.GetResource("Admin.GiftVouchers.PreventDeleted"));
        });
    }
}