move mail templates into core
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
using FluentValidation;
|
||||
using Raven.Client.Documents;
|
||||
using Raven.Client.Documents.Session;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using zero.Core.Api;
|
||||
using zero.Core.Entities;
|
||||
using zero.Core.Extensions;
|
||||
|
||||
namespace zero.Core.Api
|
||||
{
|
||||
public class MailTemplatesApi : BackofficeApi, IMailTemplatesApi
|
||||
{
|
||||
protected IValidator<IMailTemplate> Validator { get; private set; }
|
||||
|
||||
public MailTemplatesApi(IBackofficeStore store, IValidator<IMailTemplate> validator) : base(store)
|
||||
{
|
||||
Validator = validator;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IMailTemplate> GetById(string id)
|
||||
{
|
||||
return await GetById<IMailTemplate>(id);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Dictionary<string, IMailTemplate>> GetByIds(params string[] ids)
|
||||
{
|
||||
return await GetByIds<IMailTemplate>(ids);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get all available currencies
|
||||
/// </summary>
|
||||
public async Task<IList<IMailTemplate>> GetAll()
|
||||
{
|
||||
using (IAsyncDocumentSession session = Raven.OpenAsyncSession())
|
||||
{
|
||||
return await session.Query<IMailTemplate>().Scope(Scope).ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<ListResult<IMailTemplate>> GetByQuery(ListQuery<IMailTemplate> query)
|
||||
{
|
||||
query.SearchSelector = entity => entity.Name;
|
||||
|
||||
using (IAsyncDocumentSession session = Raven.OpenAsyncSession())
|
||||
{
|
||||
return await session.Query<IMailTemplate>()
|
||||
.Scope(Scope)
|
||||
.ToQueriedListAsync(query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<EntityResult<IMailTemplate>> Save(IMailTemplate model)
|
||||
{
|
||||
return await SaveModel(model, Validator);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<EntityResult<IMailTemplate>> Delete(string id)
|
||||
{
|
||||
return await DeleteById<IMailTemplate>(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface IMailTemplatesApi
|
||||
{
|
||||
/// <summary>
|
||||
/// Get mail template by id
|
||||
/// </summary>
|
||||
Task<IMailTemplate> GetById(string id);
|
||||
|
||||
/// <summary>
|
||||
/// Get mail templates by ids
|
||||
/// </summary>
|
||||
Task<Dictionary<string, IMailTemplate>> GetByIds(params string[] ids);
|
||||
|
||||
/// <summary>
|
||||
/// Get all available mail templates
|
||||
/// </summary>
|
||||
Task<IList<IMailTemplate>> GetAll();
|
||||
|
||||
/// <summary>
|
||||
/// Get all available mail templates (with query)
|
||||
/// </summary>
|
||||
Task<ListResult<IMailTemplate>> GetByQuery(ListQuery<IMailTemplate> query);
|
||||
|
||||
/// <summary>
|
||||
/// Creates or updates a mail template
|
||||
/// </summary>
|
||||
Task<EntityResult<IMailTemplate>> Save(IMailTemplate model);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a mail template by id
|
||||
/// </summary>
|
||||
Task<EntityResult<IMailTemplate>> Delete(string id);
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,7 @@
|
||||
public const string Languages = "languages";
|
||||
public const string Translations = "translations";
|
||||
public const string Countries = "countries";
|
||||
public const string Mails = "mailTemplates";
|
||||
public const string Logging = "logs";
|
||||
public const string Plugins = "plugins";
|
||||
public const string CreatePlugin = "createplugin";
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
using zero.Core.Attributes;
|
||||
using zero.Core.Entities;
|
||||
|
||||
namespace zero.Core.Entities
|
||||
{
|
||||
public class MailTemplate : ZeroEntity, IMailTemplate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public string Key { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string SenderEmail { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string SenderName { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string RecipientEmail { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Cc { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Bcc { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Subject { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Body { get; set; }
|
||||
}
|
||||
|
||||
|
||||
[Collection("MailTemplates")]
|
||||
public interface IMailTemplate : IZeroEntity, IAppAwareEntity, IZeroDbConventions
|
||||
{
|
||||
/// <summary>
|
||||
/// Alias which is used to get the template in code
|
||||
/// </summary>
|
||||
string Key { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Email address of the sender (overrides email from application)
|
||||
/// </summary>
|
||||
string SenderEmail { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the sender (overrides name from application)
|
||||
/// </summary>
|
||||
string SenderName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Email address of the recipient. This is only necessary for templates which do not have a dynamic recipient (e.g. reports).
|
||||
/// </summary>
|
||||
string RecipientEmail { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Additional comma-separated emails to send a copy to
|
||||
/// </summary>
|
||||
string Cc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Additional comma-separated emails to send a hidden copy to
|
||||
/// </summary>
|
||||
string Bcc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Email subject (can contain placeholders)
|
||||
/// </summary>
|
||||
string Subject { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Email body (can contain placeholders)
|
||||
/// </summary>
|
||||
string Body { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
public const string Languages = PREFIX + Constants.Settings.Languages;
|
||||
public const string Translations = PREFIX + Constants.Settings.Translations;
|
||||
public const string Countries = PREFIX + Constants.Settings.Countries;
|
||||
public const string Mails = PREFIX + Constants.Settings.Mails;
|
||||
public const string Logging = PREFIX + Constants.Settings.Logging;
|
||||
public const string Plugins = PREFIX + Constants.Settings.Plugins;
|
||||
public const string CreatePlugin = PREFIX + Constants.Settings.CreatePlugin;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using FluentValidation;
|
||||
using zero.Core.Entities;
|
||||
|
||||
namespace zero.Core.Validation
|
||||
{
|
||||
public class MailTemplateValidator : ZeroValidator<IMailTemplate>
|
||||
{
|
||||
public MailTemplateValidator()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user