コード例 #1
0
        public ActionResult LoadEmployees(jQueryDataTableParamModel param)
        {
            var all_emps = db.Employees;
            IEnumerable<Employee> filteredEmps;
            var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);

            Func<Employee, string> orderingFunction = (c => sortColumnIndex == 1 ? c.EmployeeFirstName : sortColumnIndex == 2 ? c.EmployeeLastName.ToString() :
                                                        c.UserID);

            if (!string.IsNullOrEmpty(param.sSearch))
            {
                filteredEmps = all_emps.Where(c => c.EmployeeFirstName.Contains(param.sSearch) || c.EmployeeLastName.Contains(param.sSearch)
                    || c.UserID.Contains(param.sSearch));
            }
            else
            {
                filteredEmps = all_emps;
            }

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

            var displayedEmps = filteredEmps
                .Skip(param.iDisplayStart)
                .Take(param.iDisplayLength);

            var result = displayedEmps
                .AsEnumerable()
                .Select(a => new List<string> { a.EmployeeID.ToString(), a.EmployeeFirstName, a.EmployeeLastName,a.UserID })
                .ToList();

            var jsonData = new
            {
                sEcho = param.sEcho,
                iTotalRecords = all_emps.Count(),
                iTotalDisplayRecords = all_emps.Count(),
                aaData = result
            };

            return Json(jsonData, JsonRequestBehavior.AllowGet);
        }
コード例 #2
0
ファイル: AssetController.cs プロジェクト: prosperva/assets
        public ActionResult LoadAssets(jQueryDataTableParamModel param)
        {
            var all_assets = db.Assets;
            IEnumerable<Asset> filteredAssets;
            var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
            Func<Asset, string> orderingFunction = (c => sortColumnIndex == 1 ? c.AssetTag :
                                                        sortColumnIndex == 2 ? c.PONumber :
                                                        c.MakeModel);


            if (!string.IsNullOrEmpty(param.sSearch)){
                filteredAssets = all_assets
                                            .Where(c => c.AssetTag.Contains(param.sSearch)||c.PONumber.Contains(param.sSearch)||c.MakeModel.Contains(param.sSearch));
            }
            else{
                filteredAssets = all_assets;
            }

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


            var displayedAssets = filteredAssets
                .Skip(param.iDisplayStart)
                .Take(param.iDisplayLength);

            var result = displayedAssets
                .AsEnumerable()
                .Select(a => new List<string> { a.AssetID.ToString(),a.AssetTag, a.PONumber, a.MakeModel })
                .ToList();

            var jsonData = new {
                sEcho = param.sEcho,
                iTotalRecords = all_assets.Count(),
                iTotalDisplayRecords = all_assets.Count(),
                aaData = result
            };

            return Json(jsonData,JsonRequestBehavior.AllowGet);
        }
コード例 #3
0
        public ActionResult LoadSoftware(jQueryDataTableParamModel param)
        {
            var all_software = db.Softwares;
            IEnumerable<Software> filteredSoftware;
            var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
            Func<Software, string> orderingFunction = (c => sortColumnIndex == 1 ? c.softwareName :
                                                        sortColumnIndex == 2 ? c.InstallNumber.ToString() :
                                                        c.OSSystem.OSSystemname);

            if (!string.IsNullOrEmpty(param.sSearch))
            {
                filteredSoftware = all_software
                                            .Where(c => c.softwareName.Contains(param.sSearch));
            }
            else
            {
                filteredSoftware = all_software;
            }

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

            var displayedSoftware = filteredSoftware
                .Skip(param.iDisplayStart)
                .Take(param.iDisplayLength);

            var result = displayedSoftware
                .AsEnumerable()
                .Select(a => new List<string> { a.SoftwareID.ToString(), a.softwareName, a.InstallNumber.ToString(), getOSName(a.OSSystemID) })
                .ToList();

            var jsonData = new{
                sEcho = param.sEcho,
                iTotalRecords = all_software.Count(),
                iTotalDisplayRecords = all_software.Count(),
                aaData = result
            };

            return Json(jsonData, JsonRequestBehavior.AllowGet);
        }