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.

885 B
Raw Blame
using FluentValidation;
using Grand.Business.Core.Interfaces.Checkout.Shipping;
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 OrderDeleteModelValidator : BaseGrandValidator<OrderDeleteModel>
{
    public OrderDeleteModelValidator(
        IEnumerable<IValidatorConsumer<OrderDeleteModel>> validators,
        IShipmentService shipmentService, ITranslationService translationService)
        : base(validators)
    {
        RuleFor(x => x).CustomAsync(async (x, context, _) =>
        {
            var shipments = await shipmentService.GetShipmentsByOrder(x.Id);
            if (shipments.Any())
                context.AddFailure("This order is in associated with shipment. Please delete it first.");
        });
    }
}