using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Mapster; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Memory; using Newtonsoft.Json.Linq; using Persistence.Database.Entity; using Persistence.Models; using Persistence.Repositories; namespace Persistence.Repository.Repositories; public class DataSourceSystemRepository : IDataSourceSystemRepository { protected DbContext db; public DataSourceSystemRepository(DbContext db) { this.db = db; } protected virtual IQueryable GetQueryReadOnly() => db.Set(); public virtual async Task Add(DataSourceSystemDto dataSourceSystemDto, CancellationToken token) { var entity = dataSourceSystemDto.Adapt(); await db.Set().AddAsync(entity, token); await db.SaveChangesAsync(token); } public virtual async Task> Get(CancellationToken token) { var query = GetQueryReadOnly(); var entities = await query.ToArrayAsync(token); var dtos = entities.Select(e => e.Adapt()); return dtos; } }