示例#1
1
        public ActionResult GetList(JQueryDataTableParamModel param)
        {
            GenderService GenderService = new GenderService();

            IEnumerable<GenderDto> allGenders = GenderService.GetAllExposeDto();

            IEnumerable<GenderDto> filteredGenders;

            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"]);

                filteredGenders = allGenders
                   .Where(c => isNameSearchable && c.Name != null && c.Name.ToString().ToLower().Contains(param.sSearch.ToLower()));
            }
            else
            {
                filteredGenders = allGenders;
            }

            var isNameSortable = Convert.ToBoolean(Request["bSortable_1"]);
            var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
            Func<GenderDto, string> orderingFunction = (c => sortColumnIndex == 1 && isNameSortable ? c.Name.ToString() :
                                                          "");

            var sortDirection = Request["sSortDir_0"]; // asc or desc
            if (sortDirection == "asc")
                filteredGenders = filteredGenders.OrderBy(orderingFunction);
            else
                filteredGenders = filteredGenders.OrderByDescending(orderingFunction);

            IEnumerable<GenderDto> displayedGenders;

            if (param.iDisplayLength != -1)
                displayedGenders = filteredGenders.Skip(param.iDisplayStart).Take(param.iDisplayLength);
            else
                displayedGenders = filteredGenders;

            var result = from c in displayedGenders
                         select new[]
                              {
                                  c.Id.ToString(),
                                  c.Name
                              };
            return Json(new
            {
                sEcho = param.sEcho,
                iTotalRecords = allGenders.Count(),
                iTotalDisplayRecords = filteredGenders.Count(),
                aaData = result
            },
                        JsonRequestBehavior.AllowGet);
        }
示例#2
0
        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);
        }