示例#1
0
        public IActionResult Index(int id, string searchString, int?page)
        {
            var locationModels = locationService.GetAll((LocationType)id).Select(l => new LocationsDetailsViewModel
            {
                Id           = l.Id,
                Name         = l.Name,
                Address      = l.Address,
                City         = l.City,
                PostCode     = l.PostCode,
                LocationType = LocationTypeEx.LocationTypes.First(lte => lte.LocationType == (int)l.Type)
            });

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                page           = 1;
                locationModels = locationModels
                                 .Where(l => l.Name.ToLower().Contains(searchString.ToLower()) ||
                                        l.Address.ToLower().Contains(searchString.ToLower()) ||
                                        l.City.ToLower().Contains(searchString.ToLower()));
            }

            int pageNumber = (page ?? 1);

            var model = new LocationsIndexViewModel
            {
                Locations = locationModels.ToPagedList(pageNumber, 9)
            };

            return(View(model));
        }
示例#2
0
        public ActionResult Index()
        {
            var model = new LocationsIndexViewModel();

            model.Locations = _locationsRepository.GetAll();

            return(View(model));
        }