public IQueryResult <User> Find(UserSearchCriteria userSearchCriteria) { if (userSearchCriteria == null) { throw new ArgumentNullException("userSearchCriteria", "must not be null."); } var constraints = new QueryConstraints <User>() .IncludePath(u => u.Roles) .Page(userSearchCriteria.PageNumber, userSearchCriteria.PageSize) .Where(c => true); if (userSearchCriteria.IsActive.HasValue) { constraints.AndAlso(c => c.IsActive == userSearchCriteria.IsActive.Value); } if (!string.IsNullOrEmpty(userSearchCriteria.FullName)) { constraints.AndAlso(c => c.FullName.Contains(userSearchCriteria.FullName)); } if (!string.IsNullOrEmpty(userSearchCriteria.Mobile)) { constraints.AndAlso(c => c.Mobile.Contains(userSearchCriteria.Mobile)); } if (!string.IsNullOrEmpty(userSearchCriteria.RoleName)) { constraints.AndAlso(c => c.Roles.Any(r => r.Name == userSearchCriteria.RoleName)); } if (!string.IsNullOrEmpty(userSearchCriteria.UserName)) { constraints.AndAlso(c => c.UserName.Contains(userSearchCriteria.UserName)); } if (!string.IsNullOrEmpty(userSearchCriteria.Email)) { constraints.AndAlso(c => c.Email.Contains(userSearchCriteria.Email)); } if (string.IsNullOrEmpty(userSearchCriteria.Sort)) { constraints.SortByDescending(c => c.CreatedAt); } //else if (userSearchCriteria.SortDirection == WebGridSortOrder.Ascending) // constraints.SortBy(userSearchCriteria.Sort); else { constraints.SortByDescending(userSearchCriteria.Sort); } return(queryRepository.Find(constraints)); }
public void TypedSortByDescending() { var constraints = new QueryConstraints <User>(); constraints.SortByDescending(x => x.FirstName); Assert.Equal(SortOrder.Descending, constraints.SortOrder); Assert.Equal("FirstName", constraints.SortPropertyName); }
public void SortByDescending() { var constraints = new QueryConstraints<User>(); constraints.SortByDescending("FirstName"); Assert.Equal(SortOrder.Descending, constraints.SortOrder); Assert.Equal("FirstName", constraints.SortPropertyName); }