コード例 #1
0
        public IPagedList <Institution> Search(InstitutionFilter filter)
        {
            var query = this.DbContext.Institutions.AsQueryable();

            if (!string.IsNullOrWhiteSpace(filter.Name))
            {
                query = query.Where(u => u.Name.ToLower().Contains(filter.Name.ToLower()));
            }

            return(ApplyOrdering(query, filter).ToPagedList(filter.PageNumber, filter.PageSize));
        }
コード例 #2
0
        private static IOrderedQueryable <Institution> ApplyOrdering(IQueryable <Institution> query, InstitutionFilter filter)
        {
            switch (filter.SortMode)
            {
            case InstitutionSortMode.Name:
                return(filter.SortDirection == SortDirection.Ascending ? query.OrderBy(u => u.Name) : query.OrderByDescending(u => u.Name));

            case InstitutionSortMode.NumberOfBaseJournalScoreCards:
                return(filter.SortDirection == SortDirection.Ascending ?
                       query.OrderBy(u => u.NumberOfBaseScoreCards).ThenBy(u => u.Name) :
                       query.OrderByDescending(u => u.NumberOfBaseScoreCards).ThenBy(u => u.Name));

            case InstitutionSortMode.NumberOfValuationJournalScoreCards:
                return(filter.SortDirection == SortDirection.Ascending ?
                       query.OrderBy(u => u.NumberOfValuationScoreCards).ThenBy(u => u.Name) :
                       query.OrderByDescending(u => u.NumberOfValuationScoreCards).ThenBy(u => u.Name));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }