Files
f9-web-ai-test/backend/F9WebAiTest.Infrastructure/FreeSqls/Repositories/SYS/Departments/DepartmentWriteRepository.cs
T
2026-10-08 10:43:59 +08:00

39 lines
1.4 KiB
C#

using FreeSql;
using F9WebAiTest.Domain.Entities.SYS.Departments;
using F9WebAiTest.Domain.Interfaces.SYS.Departments;
namespace F9WebAiTest.Infrastructure.FreeSqls.Repositories.SYS.Departments;
internal class DepartmentWriteRepository : F9RepositoryBase, IDepartmentWriteRepository
{
public DepartmentWriteRepository(IFreeSql fsql) : base(fsql) { }
public async Task<Department> GetByIdAsync(long id, CancellationToken cancellationToken)
=> await Orm.Select<Department>().Where(x => x.Id == id ).FirstAsync(cancellationToken);
public async Task<bool> AddAsync(Department dep)
{
dep.CreatedAt = DateTime.Now;
return await Orm.Insert(dep).ExecuteAffrowsAsync() > 0;
}
public async Task<bool> UpdateAsync(Department dep)
{
dep.UpdatedAt = DateTime.Now;
return await Orm.Update<Department>().SetSource(dep).ExecuteAffrowsAsync() > 0;
}
public async Task<bool> SoftDeleteAsync(long id)
=> await Orm.Update<Department>()
.Set(x => x.IsDeleted, true)
.Where(x => x.Id == id )
.ExecuteAffrowsAsync() > 0;
public async Task<bool> ActiveOrDeactive(long id, bool active)
=> await Orm.Update<Department>()
.Set(x => x.IsActive, active)
.Set(x => x.UpdatedAt, DateTime.Now)
.Where(x => x.Id == id)
.ExecuteAffrowsAsync() > 0;
}