Esempio n. 1
0
        // GET: Experience
        public ActionResult Index(string sortOrder, string currentFilter, string searchString, int?page)
        {
            ViewBag.CurrentSort = sortOrder;
            ViewBag.Name        = String.IsNullOrEmpty(sortOrder) ? "nameDescending" : "";

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            ViewBag.CurrentFilter = searchString;

            var model = _experienceService.GetAllExperiences();

            if (!String.IsNullOrEmpty(searchString))
            {
                model = model.Where(e => e.Name.ToLower().Contains(searchString.ToLower()));
            }
            switch (sortOrder)
            {
            case "nameDescending":
                model = model.OrderByDescending(m => m.Name);
                break;

            default:     // Name ascending
                model = model.OrderBy(m => m.Name);
                break;
            }

            int pageSize   = 25;
            int pageNumber = (page ?? 1);

            return(View(model.ToPagedList(pageNumber, pageSize)));
        }