using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using System.Data.Entity; using System.Data.Entity.Infrastructure; using Bowin.Common.Data; using Bowin.Common.Linq.Entity; namespace EMIS.DataLogic.Repositories.HRService { public class Repository where TEntity : class { private HRUnitOfWork _unitOfWork; private Repository() { } public Repository(HRUnitOfWork unitOfWork) { this._unitOfWork = unitOfWork; } public TEntity GetSingle(Expression> expression) { return this.Entities.Where(expression).FirstOrDefault(); } public TEntity GetSingle(Expression> expression, params string[] paths) { IQueryable source = this.Entities;//.Include(path) foreach (var path in paths) { source = source.Include(path); } return source.Where(expression).FirstOrDefault(); } public TEntity GetSingle(Expression> expression, params Expression>[] paths) { IQueryable source = this.Entities;//.Include(path) foreach (var path in paths) { source = source.Include(path); } return source.Where(expression).FirstOrDefault(); } public IQueryable Entities { get { return this._unitOfWork.Set(); } } public HRUnitOfWork UnitOfWork { get { return this._unitOfWork; } } public GridResultSet GetPagedList(Expression> expression, int pageIndex, int pageSize, Expression> orderBy, bool descending, params Expression>[] paths) { IQueryable source = this.Entities;//.Include(path) foreach (var path in paths) { source = source.Include(path); } source = source.Where(expression); source = descending ? source.OrderByDescending(orderBy) : source.OrderBy(orderBy); GridResultSet gridResult = new GridResultSet(); gridResult.rows = source.Skip((pageIndex) * pageSize).Take(pageSize).ToList(); gridResult.total = source.Count(); return gridResult; } public GridResultSet GetPagedList(Expression> expression, int pageIndex, int pageSize, Expression> orderBy, bool descending) { try { IQueryable source = this.Entities.Where(expression); source = descending ? source.OrderByDescending(orderBy) : source.OrderBy(orderBy); GridResultSet gridResult = new GridResultSet(); gridResult.rows = source.Skip((pageIndex) * pageSize).Take(pageSize).ToList(); gridResult.total = source.Count(); return gridResult; } catch (Exception ex) { throw ex; } } public IQueryable GetList(Expression> expression, Expression> orderBy, bool descending) { var source = GetList(expression); return descending ? source.OrderByDescending(orderBy) : source.OrderBy(orderBy); } public IQueryable GetList(Expression> expression) { return this.Entities.Where(expression); } public IQueryable GetList(Expression> expression, params string[] paths) { IQueryable source = this.Entities;//.Include(path) foreach (var path in paths) { source = source.Include(path); } return source.Where(expression); } public IQueryable GetList(Expression> expression, params Expression>[] paths) { IQueryable source = this.Entities;//.Include(path) foreach (var path in paths) { source = source.Include(path); } return source.Where(expression); } } }