コード例 #1
0
 private void AddFilters(PageQuery query)
 {
     query.Filters[nameof(PackageDto.Id)] = IdFilter;
     switch (PackageStatusFilter)
     {
         case PackageStatusFilter.Delivered:
             query.Filters[nameof(PackageDto.Status)] = PackageStatus.Delivered.ToString();
             break;
         case PackageStatusFilter.InDelivery:
             query.Filters[nameof(PackageDto.Status)] = PackageStatus.InDelivery.ToString();
             break;
         case PackageStatusFilter.New:
             query.Filters[nameof(PackageDto.Status)] = PackageStatus.InWarehouse.ToString();
             break;
     }
     query.Filters[nameof(PackageDto.EmployeeId)] = "User.Id";
 }
コード例 #2
0
        public void GetPagedResult_WhenSortPropertyIsNotSpecified_ShouldSortById()
        {
            var employees = new List<EmployeeDto>
            {
                new EmployeeDto {Id = 3 },
                new EmployeeDto {Id = 1 },
                new EmployeeDto {Id = 2 }
            };
            PageQuery query = new PageQuery
            {
                PageSize = 10,
                PageIndex = 1
            };

            var result = PagingHelper.GetPagedResult(employees.AsQueryable(), query);

            Assert.Equal(result.PageCollection[0].Id, 1);
            Assert.Equal(result.PageCollection[1].Id, 2);
            Assert.Equal(result.PageCollection[2].Id, 3);
        }
コード例 #3
0
        public void GetPagedResult_ShouldSortBySpecifiedProperty()
        {
            var employees = new List<EmployeeDto>
            {
                new EmployeeDto {Id = 3, FirstName= "C"},
                new EmployeeDto {Id = 1, FirstName = "A"},
                new EmployeeDto {Id = 2, FirstName = "B"}
            };
            PageQuery query = new PageQuery
            {
                PageSize = 10,
                PageIndex = 1,
                SortProperty = "FirstName"
            };

            var result = PagingHelper.GetPagedResult(employees.AsQueryable(), query);

            Assert.Equal(result.PageCollection[0].FirstName, "A");
            Assert.Equal(result.PageCollection[1].FirstName, "B");
            Assert.Equal(result.PageCollection[2].FirstName, "C");
        }
コード例 #4
0
        public void GetPagedResult_WhenSortDirectionDescending()
        {
            var employees = new List<EmployeeDto>
            {
                new EmployeeDto {Id = 3, FirstName= "C"},
                new EmployeeDto {Id = 1, FirstName = "A"},
                new EmployeeDto {Id = 2, FirstName = "B"}
            };
            PageQuery query = new PageQuery
            {
                PageSize = 10,
                PageIndex = 1,
                SortProperty = "FirstName",
                SortDirection = System.ComponentModel.ListSortDirection.Descending
            };

            var result = PagingHelper.GetPagedResult(employees.AsQueryable(), query);

            Assert.Equal(result.PageCollection[0].FirstName, "C");
            Assert.Equal(result.PageCollection[1].FirstName, "B");
            Assert.Equal(result.PageCollection[2].FirstName, "A");
        }
コード例 #5
0
 /// <summary>
 /// Zwraca stronę danych dostępnych pojazdów.
 /// </summary>
 /// <param name="query"></param>
 /// <returns></returns>
 public async Task<PagedResult<VehicleDto>> AvailableVehiclesPage(PageQuery query)
 {
     string queryString = "Available/Page?" + query.ToQueryString();
     return await Get<PagedResult<VehicleDto>>(queryString);
 }
コード例 #6
0
        public void GetPagedResult_ShouldReturnCorrectNumberOfPages()
        {
            var employees = new List<EmployeeDto>
            {
                new EmployeeDto {Id = 1},
                new EmployeeDto {Id = 2},
                new EmployeeDto {Id = 3 },
                new EmployeeDto {Id = 4 },
                new EmployeeDto {Id = 5 },
            };
            PageQuery query = new PageQuery
            {
                PageSize = 2,
                PageIndex = 1
            };

            var result = PagingHelper.GetPagedResult(employees.AsQueryable(), query);

            Assert.Equal(result.PageCount, 3);
        }
コード例 #7
0
        public void GetPagedResult_ShouldReturnPageCollectionForCorrectPage()
        {
            var employees = new List<EmployeeDto>
            {
                new EmployeeDto {Id = 1},
                new EmployeeDto {Id = 2},
                new EmployeeDto {Id = 3 },
                new EmployeeDto {Id = 4 },
                new EmployeeDto {Id = 5 },
            };
            PageQuery query = new PageQuery
            {
                PageSize = 2,
                PageIndex = 2
            };

            var result = PagingHelper.GetPagedResult(employees.AsQueryable(), query);

            Assert.Equal(result.PageCollection.Count, 2);
            Assert.Equal(result.PageCollection[0].Id, 3);
            Assert.Equal(result.PageCollection[1].Id, 4);
        }
コード例 #8
0
 /// <summary>
 /// Zwraca stronę danych przesyłek dla pracownika.
 /// </summary>
 /// <param name="query"></param>
 /// <returns></returns>
 public async Task<PagedResult<PackageDto>> PageForLoggedEmployee(PageQuery query)
 {
     string queryString = "LoggedEmployee/Page?" + query.ToQueryString();
     return await Get<PagedResult<PackageDto>>(queryString);
 }
コード例 #9
0
 /// <summary>
 /// Zwraca stronę danych dostępnych pracowników.
 /// </summary>
 /// <param name="packageId"></param>
 /// <param name="query"></param>
 /// <returns></returns>
 public async Task<PagedResult<EmployeeDto>> GetAvailableEmployeesPage(int packageId, PageQuery query)
 {
     string queryString = $"AvailableEmployees/Page?packageId={packageId}&{query.ToQueryString()}";
     return await Get<PagedResult<EmployeeDto>>(queryString);
 }
コード例 #10
0
 protected void AddFilters(PageQuery query)
 {
     if (!string.IsNullOrEmpty(RegistrationNumberFilter))
     {
         query.Filters[nameof(VehicleDto.RegistrationNumber)] = RegistrationNumberFilter;
     }
     if (!string.IsNullOrEmpty(ModelFilter))
     {
         query.Filters[nameof(VehicleDto.Model)] = ModelFilter;
     }
     if (!string.IsNullOrEmpty(BrandFilter))
     {
         query.Filters[nameof(VehicleDto.Brand)] = BrandFilter;
     }
 }
コード例 #11
0
 /// <summary>
 /// Zwraca stronę danych użytkowników.
 /// </summary>
 /// <param name="query"></param>
 /// <returns></returns>
 public async Task<PagedResult<UserDto>> Page(PageQuery query)
 {
     return await Get<PagedResult<UserDto>>("Page?" + query.ToQueryString());
 }
コード例 #12
0
 protected void AddFilters(PageQuery query)
 {
     if (!string.IsNullOrEmpty(FirstNameFilter))
     {
         query.Filters[nameof(EmployeeDto.FirstName)] = FirstNameFilter;
     }
     if (!string.IsNullOrEmpty(LastNameFilter))
     {
         query.Filters[nameof(EmployeeDto.LastName)] = LastNameFilter;
     }
     if (!string.IsNullOrEmpty(EmailFilter))
     {
         query.Filters[nameof(EmployeeDto.Email)] = EmailFilter;
     }
 }
コード例 #13
0
 /// <summary>
 /// Zwraca stronę danych pracowników z ich pojazdami.
 /// </summary>
 /// <param name="query"></param>
 /// <returns></returns>
 public async Task<PagedResult<EmployeeVehicleDto>> VehiclesPage(PageQuery query)
 {
     string queryString = "Vehicles/Page?" + query.ToQueryString();
     return await Get<PagedResult<EmployeeVehicleDto>>(queryString);
 }
コード例 #14
0
 /// <summary>
 /// Zwraca stronę danych pracowników z ich paczkami.
 /// </summary>
 /// <param name="query"></param>
 /// <returns></returns>
 public async Task<PagedResult<EmployeePackagesDto>> PackagesPage(PageQuery query)
 {
     string queryString = "Packages/Page?" + query.ToQueryString();
     return await Get<PagedResult<EmployeePackagesDto>>(queryString);
 }