38 lines
1.4 KiB
C#
38 lines
1.4 KiB
C#
using FreeSql;
|
|
using F9WebAiTest.Domain.Entities.SYS.Registries;
|
|
using F9WebAiTest.Domain.Interfaces.SYS.Registries;
|
|
|
|
namespace F9WebAiTest.Infrastructure.FreeSqls.Repositories.SYS.Registries;
|
|
|
|
internal class RegistryWriteRepository : F9RepositoryBase, IRegistryWriteRepository
|
|
{
|
|
public RegistryWriteRepository(IFreeSql fsql) : base(fsql) { }
|
|
|
|
public async Task<Registry> GetByIdAsync(long id, CancellationToken cancellationToken)
|
|
=> await Orm.Select<Registry>().Where(x => x.Id == id && x.DeletedAt == null).FirstAsync(cancellationToken);
|
|
|
|
public async Task<Registry> GetByCategoryAndKeyAsync(string category, string keyName)
|
|
=> await Orm.Select<Registry>()
|
|
.Where(x => x.DeletedAt == null && x.Category == category && x.KeyName == keyName)
|
|
.FirstAsync();
|
|
|
|
public async Task<bool> AddAsync(Registry registry)
|
|
{
|
|
registry.CreatedAt = DateTime.Now;
|
|
return await Orm.Insert(registry).ExecuteAffrowsAsync() > 0;
|
|
}
|
|
|
|
public async Task<bool> UpdateAsync(Registry registry)
|
|
{
|
|
registry.UpdatedAt = DateTime.Now;
|
|
return await Orm.Update<Registry>().SetSource(registry).ExecuteAffrowsAsync() > 0;
|
|
}
|
|
|
|
public async Task<bool> SoftDeleteAsync(long id)
|
|
=> await Orm.Update<Registry>()
|
|
.Set(x => x.IsDeleted, true)
|
|
.Set(x => x.DeletedAt, DateTime.Now)
|
|
.Where(x => x.Id == id)
|
|
.ExecuteAffrowsAsync() > 0;
|
|
}
|