Пример #1
0
        public IActionResult Index()
        {
            _service.GetOwnerList();
            IEnumerable <Vehicle> vehicleList = _ctx.Vehicles;

            return(View(vehicleList));
        }
Пример #2
0
        // GET: Users
        public async Task <IActionResult> Index(string sortOrder, string searchString,
                                                string currentFilter, int?pageNumber)
        {
            _service.GetOwnerList();
            ViewData["CurrentSort"]      = sortOrder;
            ViewData["NameSortParm"]     = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewData["VehiclesSortParm"] = sortOrder == "Vehicles" ? "Vehicles_desc" : "Vehicles";
            ViewData["CitySortParm"]     = String.IsNullOrEmpty(sortOrder) ? "city_desc" : "";
            if (searchString != null)
            {
                pageNumber = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            ViewData["CurrentFiler"] = searchString;

            var users = from u in _context.Users
                        select u;

            if (!String.IsNullOrEmpty(searchString))
            {
                users = users.Where(u => u.LastName.Contains(searchString) ||
                                    u.FirstName.Contains(searchString));
            }
            switch (sortOrder)
            {
            case "name_desc":
                users = users.OrderByDescending(u => u.LastName);
                break;

            case "city_desc":
                users = users.OrderByDescending(u => u.City);
                break;

            case "Vehicles":
                users = users.OrderBy(u => u.Vehicles);
                break;

            case "Vehicles_desc":
                users = users.OrderByDescending(u => u.Vehicles);
                break;

            default:
                users = users.OrderBy(u => u.LastName);
                break;
            }
            int pageSize = 3;

            return(View(await PaginatedList <User> .CreateAsync(users.AsNoTracking(), pageNumber ?? 1, pageSize)));
        }