using Microsoft.EntityFrameworkCore; using MTWorkHR.Core.Entities.Base; using MTWorkHR.Core.IDto; using MTWorkHR.Core.IRepositories.Base; using MTWorkHR.Infrastructure.DBContext; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Linq.Dynamic.Core; namespace MTWorkHR.Infrastructure.Repositories { public class RepositoryLog: IRepositoryLog where T : class { protected readonly HRDataContext context; private readonly DbSet dbSet; public RepositoryLog(HRDataContext _Context) { context = _Context; dbSet = context.Set(); } public async Task AddAsync(T entity) { await dbSet.AddAsync(entity); return entity; } public async Task DeleteAsync(T entity) { dbSet.Remove(entity); } public async Task> GetAllAsync() { return await dbSet.ToListAsync(); } public async Task GetByIdAsync(long id) { return await context.Set().FindAsync(id); } public IQueryable AsQueryable() { return dbSet.AsQueryable(); } public virtual async Task, int>> GetAllAsync(IPagingInputDto pagingInputDto) { var query = dbSet.AsQueryable(); if (pagingInputDto.HiddenFilter != null) { query = query.Where(pagingInputDto.HiddenFilter); } if (pagingInputDto.Filter != null) { var props = typeof(T).GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(FilterAttribute))); var condition = ""; foreach (var p in props) { condition = (condition == "" ? condition : condition + " || ") + p.Name + ".Contains(@0)"; } query = query.Where(condition, pagingInputDto.Filter); } var order = query.OrderBy(pagingInputDto.OrderByField + " " + pagingInputDto.OrderType); var page = order.Skip((pagingInputDto.PageNumber * pagingInputDto.PageSize) - pagingInputDto.PageSize).Take(pagingInputDto.PageSize); var total = await query.CountAsync(); return new Tuple, int>(await page.ToListAsync(), total); throw new NotImplementedException(); } } }