using ApiTools.Core;
|
using Furion.DatabaseAccessor;
|
using Mapster;
|
using MediatR;
|
using Microsoft.EntityFrameworkCore;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace ApiTools.CommonServer.Application
|
{
|
/// <summary>
|
/// 保存短信配置
|
/// </summary>
|
public class SaveSmsSettingCommandHandler(
|
IRepository<SmsSetting> rep
|
) :
|
IRequestHandler<SaveSmsSettingCommand, Guid>
|
{
|
private readonly IRepository<SmsSetting> rep = rep;
|
|
/// <summary>
|
/// 保存短信配置
|
/// </summary>
|
/// <param name="request"></param>
|
/// <param name="cancellationToken"></param>
|
/// <returns></returns>
|
public async Task<Guid> Handle(SaveSmsSettingCommand request, CancellationToken cancellationToken)
|
{
|
var logier = JwtUtils.GetCurrentLogier();
|
var entity = await rep.AsQueryable()
|
.Include(it => it.Accesses)
|
.Where(it => it.ChannelId == logier.ChannelId)
|
.FirstOrDefaultAsync();
|
var add = false;
|
if (entity == null)
|
{
|
entity = new SmsSetting();
|
entity.ChannelId = logier.ChannelId;
|
add = true;
|
}
|
request.Adapt(entity);
|
if (add)
|
{
|
await rep.InsertAsync(entity);
|
}
|
else
|
{
|
await rep.UpdateAsync(entity);
|
}
|
return entity.Id;
|
}
|
}
|
}
|