2021-11-23 11:35:01 +01:00
|
|
|
using FluentValidation;
|
|
|
|
|
using Raven.Client.Documents;
|
|
|
|
|
|
2021-11-24 13:56:08 +01:00
|
|
|
namespace zero.Mails;
|
2021-11-23 11:35:01 +01:00
|
|
|
|
2021-11-23 22:56:22 +01:00
|
|
|
public class MailTemplatesStore : EntityStore<MailTemplate>, IMailTemplatesStore
|
2021-11-23 11:35:01 +01:00
|
|
|
{
|
|
|
|
|
protected IMailDispatcher Dispatcher { get; set; }
|
|
|
|
|
|
|
|
|
|
|
2021-11-23 22:56:22 +01:00
|
|
|
public MailTemplatesStore(IStoreContext context, IMailDispatcher dispatcher = null) : base(context)
|
2021-11-23 11:35:01 +01:00
|
|
|
{
|
|
|
|
|
Dispatcher = dispatcher;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public async Task<MailTemplate> GetByKey(string key)
|
|
|
|
|
{
|
|
|
|
|
return await Session.Query<MailTemplate>().FirstOrDefaultAsync(x => x.Key == key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
protected override void ValidationRules(ZeroValidator<MailTemplate> 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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-11-23 22:56:22 +01:00
|
|
|
public interface IMailTemplatesStore : IEntityStore<MailTemplate>
|
2021-11-23 11:35:01 +01:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get mail template by associated key
|
|
|
|
|
/// </summary>
|
|
|
|
|
Task<MailTemplate> GetByKey(string key);
|
|
|
|
|
}
|