Пример #1
0
        public ActionResult Details(int id, string name, string content, int?categoryId, GridSortOptions gridSortOptions,
                                    [DefaultValue(1)] int page)
        {
            // Pobranie użytkownika po identyfikatorze
            var provider = _providerRepo.GetServiceProviderById(id);

            // Pobranie listy firm danego  użytkownika
            var companiesList = _companyRepo.GetCompaniesByUserId(provider.UserId);

            // Ustawienie domyślnej kolumny sortowania
            if (string.IsNullOrWhiteSpace(gridSortOptions.Column))
            {
                gridSortOptions.Column = "Id";
            }

            // Filtrowanie po kategorii firmy
            if (categoryId.HasValue)
            {
                companiesList = companiesList.Where(a => a.CategoryId == categoryId);
            }

            // Filtrowanie po nazwie firmy
            if (!string.IsNullOrWhiteSpace(name))
            {
                companiesList = companiesList.Where(a => a.Name.Contains(name));
            }

            // Filtrowanie po opisie firmy
            if (!string.IsNullOrWhiteSpace(content))
            {
                companiesList = companiesList.Where(a => a.Description.Contains(content));
            }

            // Utworzenie modelu do filtrowania firm
            var companiesFilterViewModel = new CompanyFilteredViewModel();

            companiesFilterViewModel.SelectedCategoryId = categoryId ?? -1;
            companiesFilterViewModel.Fill();

            // Stronicowanie i sortowanie listy firm
            var companiesPagedList = companiesList.OrderBy(gridSortOptions.Column, gridSortOptions.Direction)
                                     .AsPagination(page, 10);

            var companiesListContainer = new CompanyListContainerViewModel
            {
                CompanyPagedList         = companiesPagedList,
                CompanyFilteredViewModel = companiesFilterViewModel,
                GridSortOptions          = gridSortOptions
            };

            var serviceProviderCompaniesListContainer = new ServiceProviderCompaniesListContainerViewModel
            {
                Companies       = companiesListContainer,
                ServiceProvider = provider,
            };

            return(View(serviceProviderCompaniesListContainer));
        }
Пример #2
0
        //
        // GET: /Company/

        public ActionResult Index(string name, string content, int?serviceProviderId, int?categoryId, GridSortOptions gridSortOptions, [DefaultValue(1)] int page)
        {
            // Pobranie listy firm
            var companiesList = _companyRepo.GetAllCompanies();

            // Ustawienie domyślnej kolumny sortowania
            if (string.IsNullOrWhiteSpace(gridSortOptions.Column))
            {
                gridSortOptions.Column = "Id";
            }

            // Filtrowanie po użytkowniku
            if (serviceProviderId.HasValue)
            {
                companiesList = companiesList.Where(a => a.UserId == serviceProviderId);
            }

            // Filtrowanie po kategorii
            if (categoryId.HasValue)
            {
                companiesList = companiesList.Where(a => a.CategoryId == categoryId);
            }

            // Filtrowanie po nazwie
            if (!string.IsNullOrWhiteSpace(name))
            {
                companiesList = companiesList.Where(a => a.Name.Contains(name));
            }

            // Filtrowanie po treści
            if (!string.IsNullOrWhiteSpace(content))
            {
                companiesList = companiesList.Where(a => a.Description.Contains(content));
            }

            // Przygotowanie modelu do filtrowania, wypełnienie modelu danymi
            var companyFilterViewModel = new CompanyFilteredViewModel();

            companyFilterViewModel.SelectedCategoryId = categoryId ?? -1;
            companyFilterViewModel.SelectedProviderId = serviceProviderId ?? -1;
            companyFilterViewModel.Fill();

            // Sortowanie listy firm oraz stronicowanie
            var companyPagedList = companiesList.OrderBy(gridSortOptions.Column, gridSortOptions.Direction).AsPagination(page, 10);

            var companyListContainer = new CompanyListContainerViewModel
            {
                CompanyPagedList         = companyPagedList,
                CompanyFilteredViewModel = companyFilterViewModel,
                GridSortOptions          = gridSortOptions
            };

            return(View(companyListContainer));
        }