Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using Champion.Services;
- using Champion.Entities;
- using System.Net;
- using PagedList.Mvc;
- using PagedList;
- namespace Champion.Web.Controllers
- {
- public class DirectorController : Controller
- {
- // GET: Director
- public ActionResult DirectorTable(string sortOrder, string searchfirstname, string searchlastname, int? page)
- {
- ViewBag.CurrentFirstName = searchfirstname;
- ViewBag.CurrentLastName = searchlastname;
- ViewBag.CurrentSortOrder = sortOrder;
- ViewBag.FirstNameSortParam = String.IsNullOrEmpty(sortOrder) ? "FirstNameDesc" : "";
- ViewBag.LastNameSortParam = sortOrder == "LastNameAsc" ? "LastNameDesc" : "LastNameAsc";
- ViewBag.FNView = "badge badge-primary";
- ViewBag.LNView = "badge badge-primary";
- DirectorRepository DirectorRepository = new DirectorRepository();
- var Directors = DirectorRepository.GetAll();
- //======================FILTERS===============================
- //Filtering FirstName
- if (!string.IsNullOrWhiteSpace(searchfirstname))
- {
- Directors = Directors.Where(x => x.FirstName.ToUpper().Contains(searchfirstname.ToUpper()));
- }
- //Filtering LastName
- if (!string.IsNullOrWhiteSpace(searchlastname))
- {
- Directors = Directors.Where(x => x.LastName.ToUpper().Contains(searchlastname.ToUpper()));
- }
- //Sorting
- switch (sortOrder)
- {
- case "FirstNameDesc": Directors = Directors.OrderByDescending(x => x.FirstName); ViewBag.FNView = "badge badge-danger"; break;
- case "LastNameAsc": Directors = Directors.OrderBy(x => x.LastName); ViewBag.LNView = "badge badge-success"; break;
- case "LastNameDesc": Directors = Directors.OrderByDescending(x => x.LastName); ViewBag.LNView = "badge badge-danger"; break;
- default: Directors = Directors.OrderBy(x => x.FirstName); ViewBag.FNView = "badge badge-success"; break;
- }
- int pageSize = 3;
- int pageNumber = page ?? 1;
- return View(Directors.ToPagedList(pageNumber, pageSize));
- }
- // GET: TestDirectors/Details/5
- public ActionResult SimpleDetails(int? id)
- {
- DirectorRepository DirectorRepository = new DirectorRepository();
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- Director Director = DirectorRepository.GetById(id);
- if (Director == null)
- {
- return HttpNotFound();
- }
- return View(Director);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement