public ServiceDataWrapper <IList <ApplicationUserRequest> > GetAll([FromQuery] ApplicationUserFilter userFilter, [FromQuery] PaginationFilter pagination = null) { return(new ServiceDataWrapper <IList <ApplicationUserRequest> > { value = _service.GetApplicationUsersAsync(userFilter, pagination).Result }); }
/// <summary> /// /// </summary> /// <param name="filter"></param> /// <param name="queryable"></param> /// <returns></returns> private static IQueryable <ApplicationUser> AddFiltersOnQuery(ApplicationUserFilter filter, IQueryable <ApplicationUser> query) { /* * this filter is used to filter application user */ query = (!string.IsNullOrEmpty(filter?.UserName)) ? query.Where(x => x.UserName.Contains(filter.UserName)) : query; /* * */ query = (filter?.ExcludeAdmin == true) ? query.Where(x => x.UserRoles.Any(x => x.Role.Name != ApplicationConstant.ApplicationRoles.Administrator)): query; return(query); }
public async Task <IList <ApplicationUserRequest> > GetApplicationUsersAsync(ApplicationUserFilter userFilter, PaginationFilter paginationFilter) { var users = await _repository.GetApplicationUsersAsync(userFilter, paginationFilter); return(users.Select(x => new ApplicationUserRequest { Id = x.Id, UserName = x.UserName, Email = x.Email, ContactNo = x.ContactNo, Role = x.UserRoles.FirstOrDefault()?.Role?.Name, IsLocked = x.LockoutEnabled }).ToList()); }
/// <summary> /// /// </summary> /// <param name="roleName">Role Name</param> /// <param name="userFilter">User Filter</param> /// <param name="paginationFilter"></param> /// <returns></returns> public async Task <IList <ApplicationUser> > GetApplicationUsersAsync(ApplicationUserFilter userFilter, PaginationFilter paginationFilter) { var query = _context.Users.Include(u => u.UserRoles).ThenInclude(ur => ur.Role).AsQueryable(); query = AddFiltersOnQuery(userFilter, query); if (paginationFilter == null) { return(await query.ToListAsync()); } var skip = (paginationFilter.PageNumber - 1) * paginationFilter.PageSize; return(await query.Skip(skip).Take(paginationFilter.PageSize).ToListAsync()); }