/// <inheritdoc />
        public override PagedList <Order> FindAll(ResourceParameters resourceParameters)
        {
            var sortString = resourceParameters.GetFullSortString();

            var result = GetAllWithAllIncluded();

            var orderParameters = (OrderResourceParameters)resourceParameters;

            if (orderParameters.Start.Year != 1)
            {
                result = result.Where(x => x.CreatedOn.Date >= orderParameters.Start);
            }

            if (orderParameters.End.Year != 1)
            {
                result = result.Where(x => x.CreatedOn.Date <= orderParameters.End);
            }

            if (!string.IsNullOrWhiteSpace(sortString))
            {
                result = result.OrderBy(sortString);
            }

            var pagedList = PagedList <Order> .QueryAndCreate(result, resourceParameters.PageNumber, resourceParameters.PageSize);

            return(pagedList);
        }
Example #2
0
        public override PagedList <TotemEntry> FindAll(ResourceParameters resourceParameters)
        {
            IQueryable <TotemEntry> collectionBeforePaging = GetAllWithAllIncluded().AsNoTracking();

            if (!string.IsNullOrWhiteSpace(resourceParameters.Query))
            {
                var fullQuery = resourceParameters.Query.ToLowerInvariant().Trim();

                var searchTerms = fullQuery.Split(' ');

                foreach (var query in searchTerms)
                {
                    collectionBeforePaging = collectionBeforePaging.Where(x =>
                                                                          x.Totem.Naam.ToLower().Contains(query)
                                                                          | x.Adjectief.Naam.ToLower().Contains(query)
                                                                          | x.Leiding.Voornaam.ToLower().Contains(query)
                                                                          | x.Leiding.Naam.ToLower().Contains(query));
                }
            }

            //These values are calculated properties and can't be translated to SQL, we have to override our dynamic sorting. This feels very hacky though :D
            if (resourceParameters.SortBy == "reuseDateTotem" || resourceParameters.SortBy == "reuseDateAdjectief")
            {
                var property = typeof(TotemEntry).GetProperty(resourceParameters.SortBy, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);

                var newCollection = collectionBeforePaging.AsEnumerable <TotemEntry>();

                switch (resourceParameters.SortOrder)
                {
                case "asc": newCollection = newCollection.AsEnumerable().OrderBy(x => property.GetValue(x));
                    break;

                case "desc": newCollection = newCollection.AsEnumerable().OrderByDescending(x => property.GetValue(x));
                    break;
                }

                return(PagedList <TotemEntry> .QueryAndCreate(newCollection, resourceParameters.PageNumber, resourceParameters.PageSize));
            }


            //We want to sort on a database, property, back to normal.
            if (!string.IsNullOrWhiteSpace(resourceParameters.GetFullSortString()))
            {
                collectionBeforePaging = collectionBeforePaging.OrderBy(resourceParameters.GetFullSortString());
            }
            return(PagedList <TotemEntry> .QueryAndCreate(collectionBeforePaging, resourceParameters.PageNumber, resourceParameters.PageSize));
        }
        public override PagedList <Orderline> FindAll(ResourceParameters resourceParameters)
        {
            IQueryable <Orderline> result = _orderlines.Include(x => x.Order).Include(x => x.Drank)
                                            .Include(x => x.OrderedFor);
            var sortString = resourceParameters.GetFullSortString();

            var orderlineParameters = (OrderlineResourceParameters)resourceParameters;

            result = FilterOrderlinesByDates(orderlineParameters.Start, orderlineParameters.End, result);

            if (!string.IsNullOrWhiteSpace(sortString))
            {
                result = result.OrderBy(sortString);
            }

            var pagedList =
                PagedList <Orderline> .QueryAndCreate(result, orderlineParameters.PageNumber, orderlineParameters.PageSize);

            return(pagedList);
        }
        public override PagedList <Period> FindAll(ResourceParameters resourceParameters)
        {
            var sortString             = resourceParameters.GetFullSortString();
            IQueryable <Period> result = _periods;

            if (!string.IsNullOrWhiteSpace(resourceParameters.Query))
            {
                result = _periods.Where(x => x.Name.Contains(resourceParameters.Query));
            }


            if (!string.IsNullOrWhiteSpace(sortString))
            {
                result = result.OrderBy(sortString);
            }

            var pagedList =
                PagedList <Period> .QueryAndCreate(result, resourceParameters.PageNumber, resourceParameters.PageSize);

            return(pagedList);
        }