using FluentValidation; using Raven.Client.Documents; namespace zero.Collections; public class MailTemplatesCollection : EntityCollection, IMailTemplatesCollection { protected IMailDispatcher Dispatcher { get; set; } public MailTemplatesCollection(ICollectionContext context, IMailDispatcher dispatcher = null) : base(context) { Dispatcher = dispatcher; } /// public async Task GetByKey(string key) { return await Session.Query().FirstOrDefaultAsync(x => x.Key == key); } /// protected override void ValidationRules(ZeroValidator validator) { validator.RuleFor(x => x.SenderEmail).Email(); if (Dispatcher != null) { validator.RuleFor(x => x.SenderEmail).MustAsync(async (value, ct) => { return await Dispatcher.IsSenderSupported(value); }).WithMessage("@mailTemplate.errors.senderNotAllowed"); } } } public interface IMailTemplatesCollection : IEntityCollection { /// /// Get mail template by associated key /// Task GetByKey(string key); }