public GetsResult<FunctionalityDetails> Get(PageParams param) { var result = GetDefault<GetsResult<FunctionalityDetails>>(); var query = DbEntities.UserFunctionalities.OrderByDescending(x => x.Id).AsQueryable(); if (!string.IsNullOrWhiteSpace(param.Name)) query = query.Where(x => x.Name.Contains(param.Name)); result.Total = query.Count(); result.Data = query.Skip((param.Current - 1) * param.Size).Take(param.Size).Select(x => new FunctionalityDetails() { Id = x.Id, Name = x.Name, Roles = x.UserPermissions.Select(u => new IdWithName() { Id = u.UserRole.ID, Name = u.UserRole.RoleName }).ToList(), Users = x.UserPermissions.SelectMany(t => t.UserRole.UserToUserRoles.Select(z => new IdWithName() { Id = z.UserId, Name = z.User.Name })).ToList() }).ToList(); return result; }
public GetsResult<UserDetails> Get(PageParams param) { var result = GetDefault<GetsResult<UserDetails>>(); var query = DbEntities.Users.OrderByDescending(x => x.Id).AsQueryable(); if (!string.IsNullOrWhiteSpace(param.Name)) { switch (param.Type) { case 0: query = query.Where(x => x.Name.Contains(param.Name) || x.Email.Contains(param.Name)); break; case 1: query = query.Where(x => x.Name.Contains(param.Name)); break; case 2: query = query.Where(x => x.Email.Contains(param.Name)); break; } } result.Total = query.Count(); result.Data = query.Skip((param.Current - 1) * param.Size).Take(param.Size).Select(x => new UserDetails() { CreateTime = DateTime.Now, Email = x.Email, Id = x.Id, IsVerify = x.isVerify, Name = x.Name, Password = "******", Roles = x.UserToUserRoles.Select(z => new IdWithName() { Id = z.UserRole.ID, Name = z.UserRole.RoleName }).ToList() }).ToList(); return result; }