初步完成邮件功能
This commit is contained in:
158
DMS.Infrastructure/Repositories/EmailAccountRepository.cs
Normal file
158
DMS.Infrastructure/Repositories/EmailAccountRepository.cs
Normal file
@@ -0,0 +1,158 @@
|
||||
using AutoMapper;
|
||||
using DMS.Core.Interfaces.Repositories;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.Infrastructure.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SqlSugar;
|
||||
|
||||
namespace DMS.Infrastructure.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 邮件账户仓储实现
|
||||
/// </summary>
|
||||
public class EmailAccountRepository : IEmailAccountRepository
|
||||
{
|
||||
private readonly SqlSugarDbContext _dbContext;
|
||||
protected readonly ILogger<EmailAccountRepository> _logger;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public EmailAccountRepository(IMapper mapper, SqlSugarDbContext dbContext, ILogger<EmailAccountRepository> logger)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_dbContext = dbContext;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 SqlSugarClient 实例
|
||||
/// </summary>
|
||||
protected SqlSugarClient Db
|
||||
{
|
||||
get { return _dbContext.GetInstance(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认邮件账户
|
||||
/// </summary>
|
||||
public async Task<EmailAccount> GetDefaultAccountAsync()
|
||||
{
|
||||
var dbEntity = await Db.Queryable<DbEmailAccount>()
|
||||
.Where(e => e.IsDefault && e.IsActive)
|
||||
.FirstAsync();
|
||||
|
||||
return dbEntity != null ? _mapper.Map<EmailAccount>(dbEntity) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有启用的邮件账户
|
||||
/// </summary>
|
||||
public async Task<List<EmailAccount>> GetActiveAccountsAsync()
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailAccount>()
|
||||
.Where(e => e.IsActive)
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailAccount>>(dbEntities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID获取单个实体。
|
||||
/// </summary>
|
||||
public async Task<EmailAccount> GetByIdAsync(int id)
|
||||
{
|
||||
var dbEntity = await Db.Queryable<DbEmailAccount>()
|
||||
.In(id)
|
||||
.FirstAsync();
|
||||
|
||||
return dbEntity != null ? _mapper.Map<EmailAccount>(dbEntity) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取所有实体。
|
||||
/// </summary>
|
||||
public async Task<List<EmailAccount>> GetAllAsync()
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailAccount>()
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailAccount>>(dbEntities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步添加一个新实体。
|
||||
/// </summary>
|
||||
public async Task<EmailAccount> AddAsync(EmailAccount entity)
|
||||
{
|
||||
var dbEntity = _mapper.Map<DbEmailAccount>(entity);
|
||||
var result = await Db.Insertable(dbEntity)
|
||||
.ExecuteReturnEntityAsync();
|
||||
|
||||
return _mapper.Map<EmailAccount>(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步更新一个已存在的实体。
|
||||
/// </summary>
|
||||
public async Task<int> UpdateAsync(EmailAccount entity)
|
||||
{
|
||||
var dbEntity = _mapper.Map<DbEmailAccount>(entity);
|
||||
return await Db.Updateable(dbEntity)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除一个实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteAsync(EmailAccount entity)
|
||||
{
|
||||
var dbEntity = _mapper.Map<DbEmailAccount>(entity);
|
||||
return await Db.Deleteable(dbEntity)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除一个实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
return await Db.Deleteable<DbEmailAccount>()
|
||||
.In(id)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID列表批量删除实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteByIdsAsync(List<int> ids)
|
||||
{
|
||||
return await Db.Deleteable<DbEmailAccount>()
|
||||
.In(ids)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从数据库获取数据。
|
||||
/// </summary>
|
||||
public async Task<List<EmailAccount>> TakeAsync(int number)
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailAccount>()
|
||||
.Take(number)
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailAccount>>(dbEntities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步批量添加实体。
|
||||
/// </summary>
|
||||
public async Task<bool> AddBatchAsync(List<EmailAccount> entities)
|
||||
{
|
||||
var dbEntities = _mapper.Map<List<DbEmailAccount>>(entities);
|
||||
var result = await Db.Insertable(dbEntities)
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
158
DMS.Infrastructure/Repositories/EmailLogRepository.cs
Normal file
158
DMS.Infrastructure/Repositories/EmailLogRepository.cs
Normal file
@@ -0,0 +1,158 @@
|
||||
using AutoMapper;
|
||||
using DMS.Core.Interfaces.Repositories;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.Infrastructure.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SqlSugar;
|
||||
|
||||
namespace DMS.Infrastructure.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 邮件日志仓储实现
|
||||
/// </summary>
|
||||
public class EmailLogRepository : IEmailLogRepository
|
||||
{
|
||||
private readonly SqlSugarDbContext _dbContext;
|
||||
protected readonly ILogger<EmailLogRepository> _logger;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public EmailLogRepository(IMapper mapper, SqlSugarDbContext dbContext, ILogger<EmailLogRepository> logger)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_dbContext = dbContext;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 SqlSugarClient 实例
|
||||
/// </summary>
|
||||
protected SqlSugarClient Db
|
||||
{
|
||||
get { return _dbContext.GetInstance(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID获取单个实体。
|
||||
/// </summary>
|
||||
public async Task<EmailLog> GetByIdAsync(int id)
|
||||
{
|
||||
var dbEntity = await Db.Queryable<DbEmailLog>()
|
||||
.In(id)
|
||||
.FirstAsync();
|
||||
|
||||
return dbEntity != null ? _mapper.Map<EmailLog>(dbEntity) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取所有实体。
|
||||
/// </summary>
|
||||
public async Task<List<EmailLog>> GetAllAsync()
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailLog>()
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailLog>>(dbEntities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步添加一个新实体。
|
||||
/// </summary>
|
||||
public async Task<EmailLog> AddAsync(EmailLog entity)
|
||||
{
|
||||
var dbEntity = _mapper.Map<DbEmailLog>(entity);
|
||||
var result = await Db.Insertable(dbEntity)
|
||||
.ExecuteReturnEntityAsync();
|
||||
|
||||
return _mapper.Map<EmailLog>(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步更新一个已存在的实体。
|
||||
/// </summary>
|
||||
public async Task<int> UpdateAsync(EmailLog entity)
|
||||
{
|
||||
var dbEntity = _mapper.Map<DbEmailLog>(entity);
|
||||
return await Db.Updateable(dbEntity)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除一个实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteAsync(EmailLog entity)
|
||||
{
|
||||
var dbEntity = _mapper.Map<DbEmailLog>(entity);
|
||||
return await Db.Deleteable(dbEntity)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除一个实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
return await Db.Deleteable<DbEmailLog>()
|
||||
.In(id)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID列表批量删除实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteByIdsAsync(List<int> ids)
|
||||
{
|
||||
return await Db.Deleteable<DbEmailLog>()
|
||||
.In(ids)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从数据库获取数据。
|
||||
/// </summary>
|
||||
public async Task<List<EmailLog>> TakeAsync(int number)
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailLog>()
|
||||
.Take(number)
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailLog>>(dbEntities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步批量添加实体。
|
||||
/// </summary>
|
||||
public async Task<bool> AddBatchAsync(List<EmailLog> entities)
|
||||
{
|
||||
var dbEntities = _mapper.Map<List<DbEmailLog>>(entities);
|
||||
var result = await Db.Insertable(dbEntities)
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据邮件消息ID获取日志
|
||||
/// </summary>
|
||||
public async Task<List<EmailLog>> GetByEmailMessageIdAsync(int emailMessageId)
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailLog>()
|
||||
.Where(e => e.EmailMessageId == emailMessageId)
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailLog>>(dbEntities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据日期范围获取日志
|
||||
/// </summary>
|
||||
public async Task<List<EmailLog>> GetByDateRangeAsync(DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailLog>()
|
||||
.Where(e => e.CreatedAt >= startDate && e.CreatedAt <= endDate)
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailLog>>(dbEntities);
|
||||
}
|
||||
}
|
||||
}
|
||||
158
DMS.Infrastructure/Repositories/EmailMessageRepository.cs
Normal file
158
DMS.Infrastructure/Repositories/EmailMessageRepository.cs
Normal file
@@ -0,0 +1,158 @@
|
||||
using AutoMapper;
|
||||
using DMS.Core.Interfaces.Repositories;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.Infrastructure.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SqlSugar;
|
||||
|
||||
namespace DMS.Infrastructure.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 邮件消息仓储实现
|
||||
/// </summary>
|
||||
public class EmailMessageRepository : IEmailMessageRepository
|
||||
{
|
||||
private readonly SqlSugarDbContext _dbContext;
|
||||
protected readonly ILogger<EmailMessageRepository> _logger;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public EmailMessageRepository(IMapper mapper, SqlSugarDbContext dbContext, ILogger<EmailMessageRepository> logger)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_dbContext = dbContext;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 SqlSugarClient 实例
|
||||
/// </summary>
|
||||
protected SqlSugarClient Db
|
||||
{
|
||||
get { return _dbContext.GetInstance(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID获取单个实体。
|
||||
/// </summary>
|
||||
public async Task<EmailMessage> GetByIdAsync(int id)
|
||||
{
|
||||
var dbEntity = await Db.Queryable<DbEmailMessage>()
|
||||
.In(id)
|
||||
.FirstAsync();
|
||||
|
||||
return dbEntity != null ? _mapper.Map<EmailMessage>(dbEntity) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取所有实体。
|
||||
/// </summary>
|
||||
public async Task<List<EmailMessage>> GetAllAsync()
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailMessage>()
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailMessage>>(dbEntities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步添加一个新实体。
|
||||
/// </summary>
|
||||
public async Task<EmailMessage> AddAsync(EmailMessage entity)
|
||||
{
|
||||
var dbEntity = _mapper.Map<DbEmailMessage>(entity);
|
||||
var result = await Db.Insertable(dbEntity)
|
||||
.ExecuteReturnEntityAsync();
|
||||
|
||||
return _mapper.Map<EmailMessage>(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步更新一个已存在的实体。
|
||||
/// </summary>
|
||||
public async Task<int> UpdateAsync(EmailMessage entity)
|
||||
{
|
||||
var dbEntity = _mapper.Map<DbEmailMessage>(entity);
|
||||
return await Db.Updateable(dbEntity)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除一个实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteAsync(EmailMessage entity)
|
||||
{
|
||||
var dbEntity = _mapper.Map<DbEmailMessage>(entity);
|
||||
return await Db.Deleteable(dbEntity)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除一个实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
return await Db.Deleteable<DbEmailMessage>()
|
||||
.In(id)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID列表批量删除实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteByIdsAsync(List<int> ids)
|
||||
{
|
||||
return await Db.Deleteable<DbEmailMessage>()
|
||||
.In(ids)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从数据库获取数据。
|
||||
/// </summary>
|
||||
public async Task<List<EmailMessage>> TakeAsync(int number)
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailMessage>()
|
||||
.Take(number)
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailMessage>>(dbEntities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步批量添加实体。
|
||||
/// </summary>
|
||||
public async Task<bool> AddBatchAsync(List<EmailMessage> entities)
|
||||
{
|
||||
var dbEntities = _mapper.Map<List<DbEmailMessage>>(entities);
|
||||
var result = await Db.Insertable(dbEntities)
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据状态获取邮件消息
|
||||
/// </summary>
|
||||
public async Task<List<EmailMessage>> GetByStatusAsync(EmailSendStatus status)
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailMessage>()
|
||||
.Where(e => e.Status == status.ToString())
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailMessage>>(dbEntities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定时间范围内的邮件消息
|
||||
/// </summary>
|
||||
public async Task<List<EmailMessage>> GetByDateRangeAsync(DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailMessage>()
|
||||
.Where(e => e.CreatedAt >= startDate && e.CreatedAt <= endDate)
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailMessage>>(dbEntities);
|
||||
}
|
||||
}
|
||||
}
|
||||
158
DMS.Infrastructure/Repositories/EmailTemplateRepository.cs
Normal file
158
DMS.Infrastructure/Repositories/EmailTemplateRepository.cs
Normal file
@@ -0,0 +1,158 @@
|
||||
using AutoMapper;
|
||||
using DMS.Core.Interfaces.Repositories;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.Infrastructure.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SqlSugar;
|
||||
|
||||
namespace DMS.Infrastructure.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 邮件模板仓储实现
|
||||
/// </summary>
|
||||
public class EmailTemplateRepository : IEmailTemplateRepository
|
||||
{
|
||||
private readonly SqlSugarDbContext _dbContext;
|
||||
protected readonly ILogger<EmailTemplateRepository> _logger;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public EmailTemplateRepository(IMapper mapper, SqlSugarDbContext dbContext, ILogger<EmailTemplateRepository> logger)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_dbContext = dbContext;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 SqlSugarClient 实例
|
||||
/// </summary>
|
||||
protected SqlSugarClient Db
|
||||
{
|
||||
get { return _dbContext.GetInstance(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID获取单个实体。
|
||||
/// </summary>
|
||||
public async Task<EmailTemplate> GetByIdAsync(int id)
|
||||
{
|
||||
var dbEntity = await Db.Queryable<DbEmailTemplate>()
|
||||
.In(id)
|
||||
.FirstAsync();
|
||||
|
||||
return dbEntity != null ? _mapper.Map<EmailTemplate>(dbEntity) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取所有实体。
|
||||
/// </summary>
|
||||
public async Task<List<EmailTemplate>> GetAllAsync()
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailTemplate>()
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailTemplate>>(dbEntities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步添加一个新实体。
|
||||
/// </summary>
|
||||
public async Task<EmailTemplate> AddAsync(EmailTemplate entity)
|
||||
{
|
||||
var dbEntity = _mapper.Map<DbEmailTemplate>(entity);
|
||||
var result = await Db.Insertable(dbEntity)
|
||||
.ExecuteReturnEntityAsync();
|
||||
|
||||
return _mapper.Map<EmailTemplate>(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步更新一个已存在的实体。
|
||||
/// </summary>
|
||||
public async Task<int> UpdateAsync(EmailTemplate entity)
|
||||
{
|
||||
var dbEntity = _mapper.Map<DbEmailTemplate>(entity);
|
||||
return await Db.Updateable(dbEntity)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除一个实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteAsync(EmailTemplate entity)
|
||||
{
|
||||
var dbEntity = _mapper.Map<DbEmailTemplate>(entity);
|
||||
return await Db.Deleteable(dbEntity)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除一个实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
return await Db.Deleteable<DbEmailTemplate>()
|
||||
.In(id)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID列表批量删除实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteByIdsAsync(List<int> ids)
|
||||
{
|
||||
return await Db.Deleteable<DbEmailTemplate>()
|
||||
.In(ids)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从数据库获取数据。
|
||||
/// </summary>
|
||||
public async Task<List<EmailTemplate>> TakeAsync(int number)
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailTemplate>()
|
||||
.Take(number)
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailTemplate>>(dbEntities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步批量添加实体。
|
||||
/// </summary>
|
||||
public async Task<bool> AddBatchAsync(List<EmailTemplate> entities)
|
||||
{
|
||||
var dbEntities = _mapper.Map<List<DbEmailTemplate>>(entities);
|
||||
var result = await Db.Insertable(dbEntities)
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据代码获取邮件模板
|
||||
/// </summary>
|
||||
public async Task<EmailTemplate> GetByCodeAsync(string code)
|
||||
{
|
||||
var dbEntity = await Db.Queryable<DbEmailTemplate>()
|
||||
.Where(e => e.Code == code && e.IsActive)
|
||||
.FirstAsync();
|
||||
|
||||
return dbEntity != null ? _mapper.Map<EmailTemplate>(dbEntity) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有启用的邮件模板
|
||||
/// </summary>
|
||||
public async Task<List<EmailTemplate>> GetActiveTemplatesAsync()
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailTemplate>()
|
||||
.Where(e => e.IsActive)
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailTemplate>>(dbEntities);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,11 @@ public class InitializeRepository : IInitializeRepository
|
||||
_db.CodeFirst.InitTables<DbMqttServer>();
|
||||
_db.CodeFirst.InitTables<DbVariableMqttAlias>();
|
||||
_db.CodeFirst.InitTables<DbMenu>();
|
||||
_db.CodeFirst.InitTables<DbNlog>();
|
||||
_db.CodeFirst.InitTables<DbEmailAccount>();
|
||||
_db.CodeFirst.InitTables<DbEmailMessage>();
|
||||
_db.CodeFirst.InitTables<DbEmailTemplate>();
|
||||
_db.CodeFirst.InitTables<DbEmailLog>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -140,14 +145,20 @@ public class InitializeRepository : IInitializeRepository
|
||||
},
|
||||
new DbMenu
|
||||
{
|
||||
Id = 6, Header = "设置", Icon = "\uE713", ParentId = 0,
|
||||
MenuType = MenuType.MainMenu, TargetViewKey = "SettingView",
|
||||
Id = 6, Header = "邮件管理", Icon = "\uE715", ParentId = 0,
|
||||
MenuType = MenuType.MainMenu, TargetViewKey = "EmailManagementView",
|
||||
DisplayOrder = 6
|
||||
},
|
||||
new DbMenu
|
||||
{
|
||||
Id = 7, Header = "关于", Icon = "\uE946", ParentId = 0,
|
||||
MenuType = MenuType.MainMenu, TargetViewKey = "", DisplayOrder = 7
|
||||
Id = 7, Header = "设置", Icon = "\uE713", ParentId = 0,
|
||||
MenuType = MenuType.MainMenu, TargetViewKey = "SettingView",
|
||||
DisplayOrder = 7
|
||||
},
|
||||
new DbMenu
|
||||
{
|
||||
Id = 8, Header = "关于", Icon = "\uE946", ParentId = 0,
|
||||
MenuType = MenuType.MainMenu, TargetViewKey = "", DisplayOrder = 8
|
||||
} // 假设有一个AboutView
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user