コード例 #1
0
        public async Task <OkObjectResult> GetPackages(PackageFilterViewModel searchParams)
        {
            var serviceModel = PackageFilterServiceModel.FromViewModel(searchParams);
            var entities     = _services.GetPackages(serviceModel);
            var pageList     = await PaginatedList <Package> .CreateAsync(entities, searchParams.Page, searchParams.PageSize);

            var result = new PageEntityViewModel <Package, PackageViewModel>(pageList, entity => PackageViewModel.FromEntity(entity));

            return(Ok(result));
        }
コード例 #2
0
        public async Task <ObjectResult> GetPackages(PackageFilterViewModel viewModel)
        {
            var serviceModel = PackageFilterServiceModel.FromViewModel(viewModel);

            var entities = _packageService.GetPackages(serviceModel);

            if (string.IsNullOrEmpty(viewModel.SortField) == false)
            {
                if (viewModel.SortField == "title")
                {
                    entities = (viewModel.SortOrder == "ascend") ? entities.OrderBy(o => o.Details.FirstOrDefault().Title) : entities.OrderByDescending(o => o.Details.FirstOrDefault().Title);
                }
            }

            var result = await PaginatedList <Package> .CreateAsync(entities, serviceModel.Page, serviceModel.PageSize);

            var viewModels = new PageEntityViewModel <Package, PackageViewModel>(result, o => PackageViewModel.FromEntity(o));

            return(Ok(viewModels));
        }