Beispiel #1
0
        public void Fill()
        {
            CategoryRepository        _categoryRepo        = new CategoryRepository();
            ServiceProviderRepository _serviceProviderRepo = new ServiceProviderRepository();

            //Categories = new SelectList(_categoryRepo.GetAllCategories(), "CategoryId", "Name", SelectedCategoryId);
            //ServiceProvider = new SelectList(_serviceProviderRepo.GetAllServiceProvider(), "ServiceProviderId", "Name", SelectedServiceProviderId);

            Categories      = new SelectList(_categoryRepo.GetAllCategories(), "CategoryId", "Name", SelectedCategoryId);
            ServiceProvider = new SelectList(_serviceProviderRepo.GetAllServiceProvider(), "ServiceProviderId", "Name", SelectedServiceProviderId);
        }
        public ActionResult Index(string Name, string City, string Street, GridSortOptions sort,
                                  [DefaultValue(1)] int page)
        {
            IQueryable <ServiceProviderViewModel> providers = _serviceProviderRepo.GetAllServiceProvider();

            if (!User.IsInRole("administrator"))
            {
                providers.Where(s => s.IsConfirmed == true);
            }

            if (string.IsNullOrWhiteSpace(sort.Column))
            {
                sort.Column = "ServiceProviderId";
            }

            if (!string.IsNullOrWhiteSpace(Name))
            {
                providers = providers.Where(c => c.Name.Contains(Name));
            }

            if (!string.IsNullOrWhiteSpace(City))
            {
                providers = providers.Where(c => c.City.Contains(City));
            }

            if (!string.IsNullOrWhiteSpace(Street))
            {
                providers = providers.Where(c => c.Street.Contains(Street));
            }

            //potrzebna przestrzen nazw using MvcContrib.Sorting;  using MvcContrib.Pagination;
            var serviceProviderPagedList = providers.OrderBy(sort.Column, sort.Direction).AsPagination(page, 5);

            ServiceProviderFilterViewModel serviceProviderFilterViewModel = new ServiceProviderFilterViewModel();

            ServiceProviderListContainerViewModel customerListContainerViewModel = new ServiceProviderListContainerViewModel
            {
                ServiceProviderPagedList       = serviceProviderPagedList,
                ServiceProviderFilterViewModel = serviceProviderFilterViewModel,
                GridSortOptions = sort
            };

            return(View(customerListContainerViewModel));
        }