Beispiel #1
0
        public ActionResult Index(string firstName, string lastName, string city, string street, GridSortOptions gridSortOptions, [DefaultValue(1)] int page)
        {
            // Pobranie listy użytkowników
            var customersList = _customerRepo.GetAllCustomers();

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

            // Filtrowanie po imieniu
            if (!string.IsNullOrWhiteSpace(firstName))
            {
                customersList = customersList.Where(a => a.FirstName.Contains(firstName));
            }

            // Filtrowanie po nazwisku
            if (!string.IsNullOrWhiteSpace(lastName))
            {
                customersList = customersList.Where(a => a.LastName.Contains(lastName));
            }

            // Filtrowanie po mieście
            if (!string.IsNullOrWhiteSpace(city))
            {
                customersList = customersList.Where(a => a.City.Contains(city));
            }

            // Filtrowanie po ulicy
            if (!string.IsNullOrWhiteSpace(street))
            {
                customersList = customersList.Where(a => a.Street.Contains(street));
            }

            var customerFilterViewModel = new CustomerFilterViewModel();

            // Sortowanie listy użytkowników oraz stronicowanie
            var customerPagedList = customersList.OrderBy(gridSortOptions.Column, gridSortOptions.Direction)
                                    .AsPagination(page, 5);

            CustomerListContainerViewModel customerListContainer = new CustomerListContainerViewModel
            {
                CustomerPagedList       = customerPagedList,
                CustomerFilterViewModel = customerFilterViewModel,
                GridSortOptions         = gridSortOptions
            };

            return(View(customerListContainer));
        }
Beispiel #2
0
        public ActionResult Index(string FirstName, string LastName, string City, string Street, GridSortOptions sort, [DefaultValue(1)] int page)
        {
            IQueryable <CustomerViewModel> customerList = _customerRepo.GetAllCustomer();

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

            if (!string.IsNullOrWhiteSpace(FirstName))
            {
                customerList = customerList.Where(c => c.FirstName.Contains(FirstName));
            }

            if (!string.IsNullOrWhiteSpace(LastName))
            {
                customerList = customerList.Where(c => c.LastName.Contains(LastName));
            }

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

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

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

            CustomerFilterViewModel customerFilterViewModel = new CustomerFilterViewModel();

            CustomerListContainerViewModel customerListContainerViewModel = new CustomerListContainerViewModel
            {
                CustomerPageList        = customerPagedList,
                CustomerFilterViewModel = customerFilterViewModel,
                GridSortOptions         = sort
            };

            return(View(customerListContainerViewModel));
        }