Exemple #1
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");
        }
Exemple #2
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");
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
Exemple #5
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);
        }
        public IHttpActionResult GetAllAvailable([FromUri] PageQuery query)
        {
            var vehicles = context.Vehicles
                           .Include(v => v.VehicleModel)
                           .Where(v => context.Employees.Count(e => e.Vehicle.Id == v.Id) == 0)
                           .AsQueryable();
            var dtos = vehicles.ProjectTo <VehicleDto>();

            return(Ok(PagingHelper.GetPagedResult(dtos, query)));
        }
        public IHttpActionResult PackagesPage([FromUri] PageQuery query, string firstName = "",
                                              string lastName = "", string email = "")
        {
            var employees = GetAllCouriers();

            employees = ApplyFilters(employees, firstName, lastName, email);
            var dtos = employees.Include(e => e.Packages)
                       .ProjectTo <EmployeePackagesDto>();

            return(Ok(PagingHelper.GetPagedResult(dtos, query)));
        }
        public IHttpActionResult GetAvailableEmployeesPage(int packageId, [FromUri] PageQuery query)
        {
            var package   = context.Packages.Find(packageId);
            var employees = context.Employees.Where(
                e => e.Vehicle != null &&
                (double)(e.Packages.Where(p => p.Id != packageId).Sum(p => p.Weight) + package.Weight) <
                e.Vehicle.VehicleModel.Payload)
                            .ProjectTo <EmployeeDto>();

            return(Ok(PagingHelper.GetPagedResult(employees, query)));
        }
        public IHttpActionResult GetPage([FromUri] PageQuery query, string registrationNumber = "",
                                         string model = "", string brand = "")
        {
            var vehicles = context.Vehicles
                           .Include(v => v.VehicleModel)
                           .AsQueryable();

            vehicles = ApplyFilters(vehicles, registrationNumber, brand, model);
            var dtos = vehicles.ProjectTo <VehicleDto>();

            return(Ok(PagingHelper.GetPagedResult(dtos, query)));
        }
Exemple #10
0
        public IHttpActionResult GetPage([FromUri] PageQuery query)
        {
            var dtos = context.Employees.Include(e => e.User)
                       .AsQueryable()
                       .Where(e => e.User != null)
                       .ProjectTo <UserDto>();
            var result = PagingHelper.GetPagedResult(dtos, query);

            foreach (var dto in result.PageCollection)
            {
                dto.Role = (Role)Enum.Parse(typeof(Role), userManager.GetRoles(dto.Id).First());
            }
            return(Ok(result));
        }
        public IHttpActionResult GetPageForLoggedEmployee([FromUri] PageQuery query, string id = "",
                                                          PackageStatusFilter status           = PackageStatusFilter.All, string employeeId = "")
        {
            var packages = context.Set <Package>().AsQueryable();

            var userId   = User.Identity.GetUserId();
            var employee = context.Employees.AsQueryable().FirstOrDefault(e => e.User.Id == userId);

            if (employee != null)
            {
                packages = employee.Packages.AsQueryable();
            }

            packages = ApplyFilters(packages, id, status);
            var dtos = packages.ProjectTo <PackageDto>();

            return(Ok(PagingHelper.GetPagedResult(dtos, query)));
        }
        public IHttpActionResult GetPage([FromUri] PageQuery query, string id = "",
                                         PackageStatusFilter status           = PackageStatusFilter.All, string employeeId = "")
        {
            var packages = context.Set <Package>().AsQueryable();

            if (!string.IsNullOrEmpty(employeeId))
            {
                int numericEmployeeId;
                if (int.TryParse(employeeId, out numericEmployeeId))
                {
                    var employee = context.Employees.Find(numericEmployeeId);
                    if (employee != null)
                    {
                        packages = employee.Packages.AsQueryable();
                    }
                }
            }
            packages = ApplyFilters(packages, id, status);
            var dtos = packages.ProjectTo <PackageDto>();

            return(Ok(PagingHelper.GetPagedResult(dtos, query)));
        }
Exemple #13
0
        public IHttpActionResult PackagesPage([FromUri] PageQuery query)
        {
            var customer = context.Customers.FirstOrDefault(c => c.User.UserName == User.Identity.Name);

            if (customer == null)
            {
                return(BadRequest());
            }
            var dtos = customer.Packages
                       .AsQueryable()
                       .ProjectTo <PackageCustomerDto>();

            query.SortProperty  = "Id";
            query.SortDirection = ListSortDirection.Descending;
            var page = PagingHelper.GetPagedResult(dtos, query);

            foreach (var dto in page.PageCollection)
            {
                dto.StatusDescription = dto.Status.GetDescription();
            }
            return(Ok(page));
        }
Exemple #14
0
        public async Task <IActionResult> Index(int page = 1)
        {
            var totalCount = await this.FooService.GetTotalCountAsync();

            var from = totalCount.Equals(0)
                ? 1
                : (page - 1) * PageSize + 1;

            var fooCollection = await this.FooService.GetCollectionAsync(from, PageSize, true);

            var viewModel = new FooListViewModel
            {
                FooViewModels = PagingHelper.GetPagedResult <FooViewModel>
                                (
                    page,
                    PageSize,
                    totalCount,
                    this._mapper.Map <List <FooObject>, List <FooViewModel> >(fooCollection)
                                )
            };

            return(View(viewModel));
        }