using Abp.Collections.Extensions; using SnapshotWinFormsApp.Entities.NewHotline; using SnapshotWinFormsApp.Repository.Interfaces; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SnapshotWinFormsApp.Repository; public class BaseRepository : IBaseRepository where T : Entity, new() { private readonly SqlSugarClient _db; public BaseRepository(DbSqlServer context, string key) { _db = context.DbItems.GetValueOrDefault(key + "PGSQLDB"); } public async Task> GetAllAsync(CancellationToken token) { return _db.Queryable().ToList(); } public T GetById(int id) { return _db.Queryable().InSingle(id); } public async Task InsertAsync(T entity, CancellationToken token) { if (entity.Id.IsNullOrEmpty()) entity.InitId(); await _db.Insertable(entity).ExecuteCommandAsync(token); return entity.Id; } public ISugarQueryable Queryable() { return _db.Queryable(); } public void Update(T entity) { _db.Updateable(entity).ExecuteCommand(); } }