public ActionResult GetList(JQueryDataTableParamModel param) { ChucDanhService chucDanhService = new ChucDanhService(); IEnumerable<ChucDanhDto> allChucDanhs = chucDanhService.GetAllExposeDto(); IEnumerable<ChucDanhDto> filteredChucDanhs; if (!string.IsNullOrEmpty(param.sSearch)) { //Used if particulare columns are filtered var nameFilter = Convert.ToString(Request["sSearch_1"]); //Optionally check whether the columns are searchable at all var isNameSearchable = Convert.ToBoolean(Request["bSearchable_1"]); filteredChucDanhs = allChucDanhs .Where(c => isNameSearchable && c.Name != null && c.Name.ToString().ToLower().Contains(param.sSearch.ToLower())); } else { filteredChucDanhs = allChucDanhs; } var isNameSortable = Convert.ToBoolean(Request["bSortable_1"]); var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]); Func<ChucDanhDto, string> orderingFunction = (c => sortColumnIndex == 1 && isNameSortable ? c.Name.ToString() : ""); var sortDirection = Request["sSortDir_0"]; // asc or desc if (sortDirection == "asc") filteredChucDanhs = filteredChucDanhs.OrderBy(orderingFunction); else filteredChucDanhs = filteredChucDanhs.OrderByDescending(orderingFunction); IEnumerable<ChucDanhDto> displayedChucDanhs; if (param.iDisplayLength != -1) displayedChucDanhs = filteredChucDanhs.Skip(param.iDisplayStart).Take(param.iDisplayLength); else displayedChucDanhs = filteredChucDanhs; var result = from c in displayedChucDanhs select new[] { c.Id.ToString(), c.Name }; return Json(new { sEcho = param.sEcho, iTotalRecords = allChucDanhs.Count(), iTotalDisplayRecords = filteredChucDanhs.Count(), aaData = result }, JsonRequestBehavior.AllowGet); }
public ActionResult Index() { PersonModel model = new PersonModel(); GenderService genderService = new GenderService(); DepartmentService departmentService = new DepartmentService(); ChucDanhService chucDanhService = new ChucDanhService(); PersonService personService = new PersonService(); model.Departments = departmentService.GetAll().ToList(); model.Departments.Insert(0, new Department() { Id = -1, Name = "Tất cả"}); model.ChucDanhs = chucDanhService.GetAll().ToList(); model.ReportDate = System.DateTime.Now.ToShortDateString(); model.ListOfFilterNames = new List<FilterName>(); model.ListOfFilterNames.Add(new FilterName() { Id = 1, Name = "Đang công tác" }); model.ListOfFilterNames.Add(new FilterName() { Id = 2, Name = "Thôi việc" }); model.ListOfFilterNames.Add(new FilterName() { Id = 3, Name = "Tất cả" }); model.Genders = genderService.GetAll().ToList(); return View(model); }