using FreeSql; using System.Linq.Expressions; using Znyc.CloudCar.Auth.HttpContextUser; namespace Znyc.CloudCar.Repository { public abstract class RepositoryBase : BaseRepository where TEntity : class, new() { private readonly IHttpContextUser _user; protected RepositoryBase(UnitOfWorkManager uowm, IHttpContextUser user) : base(uowm.Orm, null) { uowm.Binding(this); _user = user; } /// /// 获取Dto /// /// /// /// public virtual Task GetAsync(TKey id) { return Select.WhereDynamic(id).ToOneAsync(); } /// /// 根据条件获取实体 /// /// /// public virtual Task GetAsync(Expression> exp) { return Select.Where(exp).ToOneAsync(); } /// /// 根据条件获取Dto /// /// /// /// public virtual Task GetAsync(Expression> exp) { return Select.Where(exp).ToOneAsync(); } /// /// 软删除 /// /// /// public virtual async Task SoftDeleteAsync(TKey id) { await UpdateDiy .SetDto(new { IsDeleted = true, ModifiedUserId = _user.Id }) .WhereDynamic(id) .ExecuteAffrowsAsync(); return true; } /// /// 批量软删除 /// /// /// public virtual async Task SoftDeleteAsync(TKey[] ids) { await UpdateDiy .SetDto(new { IsDeleted = true, ModifiedUserId = _user.Id }) .WhereDynamic(ids) .ExecuteAffrowsAsync(); return true; } } public abstract class RepositoryBase : RepositoryBase where TEntity : class, new() { protected RepositoryBase(UnitOfWorkManager uowm, IHttpContextUser user) : base(uowm, user) { } } }