public ActionResult Contacts(int?page, string jobTitle = "", string sortBy = "", string sort = "") { if (string.IsNullOrEmpty(sortBy)) { sortBy = "姓名"; } var contacts = RepoContact.All(jobTitle).Include(客 => 客.客戶資料); if (sortBy == "客戶名稱") { if (sort.StartsWith("desc")) { contacts = contacts.OrderByDescending(c => c.客戶資料.客戶名稱); } else { contacts = contacts.OrderBy(c => c.客戶資料.客戶名稱); } } else { var param = Expression.Parameter(typeof(客戶聯絡人), "customer"); var sortExp = Expression.Lambda <Func <客戶聯絡人, object> >(Expression.Property(param, sortBy), param); if (sort.StartsWith("desc")) { contacts = contacts.OrderByDescending(sortExp); } else { contacts = contacts.OrderBy(sortExp); } } var pageNumber = page ?? 1; var pageSize = 2; var onePaeeOfContacts = contacts.ToPagedList(pageNumber, pageSize); ViewBag.OnePageOfContacts = onePaeeOfContacts; return(PartialView("ContactListPartial")); }
public ActionResult GetAllJobTitles() { var allJobTitles = RepoContact.All().Select(c => c.職稱).Distinct(); return(this.Json(allJobTitles)); }