Exemple #1
0
        public async Task <ActionResult <List <GetUserModel> > > Get(string query = null, int page = 1, int pageSize = 50)
        {
            var users = _userRepository.TableNoTracking
                        .Where(x => (string.IsNullOrEmpty(query) || x.FirstName.Contains(query) || x.LastName.Contains(query)))
                        .OrderBy(x => x.FirstName)
                        .ThenBy(x => x.LastName)
                        .ProjectTo <GetUserModel>(_mapper.ConfigurationProvider);

            var pagedResponse = new PagedResponse <GetUserModel>(pageSize, page);
            await pagedResponse.PaginateResultsAsync(users);

            AddPaginationResponseHeaders(pagedResponse);

            return(Ok(pagedResponse.Data));
        }
Exemple #2
0
        public async Task <ActionResult <List <RoadModel> > > Get(string query = null, int?typeId = null, int page = 1, int pageSize = 50)
        {
            var roads = _roadRepository.TableNoTracking
                        .Where(x => (string.IsNullOrEmpty(query) || x.Name.Contains(query) || x.ReportingMarks.Contains(query)) &&
                               (!typeId.HasValue || x.RoadTypeId == typeId.Value))
                        .OrderBy(x => x.Name)
                        .ProjectTo <RoadModel>(_mapper.ConfigurationProvider);

            // TODO: Not sure if i Like this or not, but we'll see how it works
            var pagedResponse = new PagedResponse <RoadModel>(pageSize, page);
            await pagedResponse.PaginateResultsAsync(roads);

            AddPaginationResponseHeaders(pagedResponse);

            return(Ok(pagedResponse.Data));
        }
Exemple #3
0
        public async Task <ActionResult <List <LocomotiveModel> > > Get(int?roadId = null, string roadNumber = null, string modelNumber = null, string serialNumber = null, int page = 1, int pageSize = 50)
        {
            var locomotives = _locomotiveRepository.TableNoTracking
                              .Include(x => x.Road)
                              .Where(x => (!roadId.HasValue || x.RoadId == roadId) &&
                                     (string.IsNullOrEmpty(roadNumber) || x.ReportingMarks.Contains(roadNumber)) // TODO: Ideally don't want to do a contains here
                                                                                                                 // ... but the road rpt marks are part of the road number, so we have to for now...
                                     && (string.IsNullOrEmpty(modelNumber) || x.ModelNumber == modelNumber) &&
                                     (string.IsNullOrEmpty(serialNumber) || x.SerialNumber == serialNumber))
                              .OrderBy(x => x.Road.Name)
                              .ThenBy(x => x.RoadNumber)
                              .ProjectTo <LocomotiveModel>(_mapper.ConfigurationProvider);

            var pagedResponse = new PagedResponse <LocomotiveModel>(pageSize, page);
            await pagedResponse.PaginateResultsAsync(locomotives);

            AddPaginationResponseHeaders(pagedResponse);

            return(Ok(locomotives));
        }