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.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
using FluentValidation;
using Grand.Business.Core.Interfaces.Checkout.CheckoutAttributes;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Validators;
using Grand.Web.AdminShared.Models.Orders;
namespace Grand.Web.AdminShared.Validators.Orders;
public class CheckoutAttributeValueValidator : BaseGrandValidator<CheckoutAttributeValueModel>
{
public CheckoutAttributeValueValidator(
IEnumerable<IValidatorConsumer<CheckoutAttributeValueModel>> validators,
ICheckoutAttributeService checkoutAttributeService,
ITranslationService translationService)
: base(validators)
{
RuleFor(x => x.Name).NotEmpty()
.WithMessage(translationService.GetResource("Admin.Orders.CheckoutAttributes.Values.Fields.Name.Required"));
RuleFor(x => x).CustomAsync(async (x, context, _) =>
{
var checkoutAttribute = await checkoutAttributeService.GetCheckoutAttributeById(x.CheckoutAttributeId);
if (checkoutAttribute is { AttributeControlTypeId: AttributeControlType.ColorSquares }
&& string.IsNullOrEmpty(x.ColorSquaresRgb))
context.AddFailure("Color is required");
});
}
}