public ResultPvo <LoginLogPvo> GetWithPages(QueryBase queryBase, Expression <Func <LoginLogPvo, bool> > exp, string orderby, string orderDir = "desc") { using (var scope = _dbScopeFactory.CreateReadOnly()) { var db = GetDb(scope); var dbSet = GetDbSet(db); var where = exp.Cast <LoginLogPvo, LoginLogEntity, bool>(); var query = GetQuery(dbSet, where, orderby, orderDir); var query_count = query.FutureCount(); var query_list = query.Skip(queryBase.Start).Take(queryBase.Length).Future(); var list = query_list.ToList(); var pvo = new ResultPvo <LoginLogPvo> { recordsTotal = query_count.Value, data = Mapper.Map <List <LoginLogEntity>, List <LoginLogPvo> >(list) }; return(pvo); } }
public ResultPvo <MenuPvo> GetWithPages <OrderKeyType>(QueryBase queryBase, Expression <Func <MenuPvo, bool> > exp, Expression <Func <MenuPvo, OrderKeyType> > orderExp, bool isDesc = true) { using (var scope = _dbScopeFactory.CreateReadOnly()) { var db = GetDb(scope); var dbSet = GetDbSet(db); var where = exp.Cast <MenuPvo, MenuEntity, bool>(); var order = orderExp.Cast <MenuPvo, MenuEntity, OrderKeyType>(); var query = GetQuery(dbSet, where, order, isDesc); var query_count = query.FutureCount(); var query_list = query.Skip(queryBase.Start).Take(queryBase.Length).Future(); var list = query_list.ToList(); var dto = new ResultPvo <MenuPvo> { recordsTotal = query_count.Value, data = Mapper.Map <List <MenuEntity>, List <MenuPvo> >(list) }; return(dto); } }
public ResultPvo <RolePvo> GetNotMyRoles(QueryBase query, int userId) { using (var scope = _dbScopeFactory.CreateReadOnly()) { var db = scope.DbContexts.Get <StoreContext>(); var userRoleDbSet = db.Set <UserRoleEntity>().AsNoTracking().OrderBy(item => item.CreateTime).Where(item => item.UserId == userId).ToList(); var roleIds = userRoleDbSet.Select(item => item.RoleId).Distinct().ToList(); Expression <Func <RolePvo, bool> > exp = item => (!item.IsDelete && !roleIds.Contains(item.Id)); if (!query.SearchKey.IsBlank()) { exp = exp.And(item => item.Name.Contains(query.SearchKey)); } var where = exp.Cast <RolePvo, RoleEntity, bool>(); var roleDbSet = db.Set <RoleEntity>().AsNoTracking().OrderBy(item => item.CreateTime).Where(where); var list = roleDbSet.Skip(query.Start).Take(query.Length).ToList(); var pvo = new ResultPvo <RolePvo> { recordsTotal = roleDbSet.Count(), data = Mapper.Map <List <RoleEntity>, List <RolePvo> >(list) }; return(pvo); } }