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.GiftVouchers;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Validators;
using Grand.SharedKernel.Extensions;
using Grand.Web.AdminShared.Models.Orders;
namespace Grand.Web.AdminShared.Validators.Orders;
public class GiftVoucherNotifyRecipientValidator : BaseGrandValidator<GiftVoucherNotifyRecipient>
{
public GiftVoucherNotifyRecipientValidator(
IEnumerable<IValidatorConsumer<GiftVoucherNotifyRecipient>> validators,
IGiftVoucherService giftVoucherService)
: base(validators)
{
RuleFor(x => x).CustomAsync(async (x, context, _) =>
{
var giftVoucher = await giftVoucherService.GetGiftVoucherById(x.Id);
if (giftVoucher.GiftVoucherTypeId == GiftVoucherType.Physical)
context.AddFailure("Only virtual type gift voucher can notify recipient");
if (!CommonHelper.IsValidEmail(giftVoucher.RecipientEmail))
context.AddFailure("Recipient email is not valid");
if (!CommonHelper.IsValidEmail(giftVoucher.SenderEmail))
context.AddFailure("Sender email is not valid");
});
}
}