using Core.Blueprint.DAL.Infrastructure.Context; using Core.Blueprint.DAL.Infrastructure.Contracts; using Core.Blueprint.Domain.Entities; namespace Core.Blueprint.DAL.Infrastructure.Repository { public abstract class RepositorySqlBase : IRepositoryIdentityBase where T: AbsEntity { protected SqlServerContext _dbContext; protected RepositorySqlBase(SqlServerContext dbContext) { _dbContext = dbContext; } public async ValueTask CreateAsync(T blueprint) { blueprint.Id = Guid.NewGuid().ToString(); _dbContext.Add(blueprint); await _dbContext.SaveChangesAsync(); return blueprint; } public async Task DeleteAsync(string id) { var item = await GetByIdAsync(id); if (item == null) { return false; } _dbContext.Remove(item); await _dbContext.SaveChangesAsync(); return true; } public async ValueTask> GetAllAsync() { return _dbContext.Set(); } public async ValueTask GetByIdAsync(string id) { var result = await _dbContext.FindAsync(id); return result; } public async Task UpdateAsync(string id, T entity) { _dbContext.Update(entity); await _dbContext.SaveChangesAsync(); return true; } } }