Exemplo n.º 1
0
        public async Task <BaseJsonResult> GetPackages(PackageFilterViewModel viewModel)
        {
            var serviceModel = viewModel.ToServiceModel();
            var entities     = await _packageService.GetPackages(serviceModel);

            var viewModels = new PageEntityViewModel <Package, PackageViewModel>(entities, o => ToPackageViewModel(o));

            return(new BaseJsonResult(Omi.Base.Properties.Resources.POST_SUCCEEDED, viewModels));
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
 public static PackageFilterServiceModel FromViewModel(PackageFilterViewModel viewModel)
 => new PackageFilterServiceModel
 {
     SortBy      = viewModel.SortBy,
     BudgetMax   = viewModel.BudgetMax,
     BudgetMin   = viewModel.BudgetMin,
     TaxonomyIds = new List <long>()
     {
         viewModel.DesignTheme,
         viewModel.HouseType
     },
     Page     = viewModel.Page,
     PageSize = viewModel.PageSize,
     GetTypes = viewModel.GetTypes,
     Title    = viewModel.Title
 };
        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));
        }