using Azure; using Microsoft.EntityFrameworkCore; using MTWorkHR.Core.Entities.Base; using MTWorkHR.Core.IRepositories.Base; using MTWorkHR.Infrastructure.Data; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MTWorkHR.Infrastructure.Repositories { public class Repository : IRepository where T : Entity { protected readonly HRDataContext _context; private readonly DbSet dbSet; public Repository(HRDataContext context) { _context = context; dbSet = context.Set(); } public async Task AddAsync(T entity) { await _context.AddAsync(entity); await _context.SaveChangesAsync(); return entity; } public async Task> AddRangeAsync(IList entities) { await dbSet.AddRangeAsync(entities); return entities; } public async Task DeleteAsync(T entity) { dbSet.Remove(entity); } public async Task DeleteRangeAsync(IEnumerable entities) { dbSet.RemoveRange(entities); } public async Task, int>> GetAllAsync() { var query = dbSet.AsQueryable(); var total = await query.CountAsync(); return new Tuple, int>(await query.ToListAsync(), total); } public async Task GetByIdAsync(long id) { return await _context.Set().FindAsync(id); } } }