public JsonResult getSalaryDeduction(int PageIndex, int PageSize, string Search, string Sort) { using (PayRoll_Entities dataContext = new PayRoll_Entities()) { ArrayList paramList = new ArrayList(); var salaryDeductionList = dataContext.SalaryDeduction_tbl.Select(c => new { c.id, c.DeductionType, c.Create_by, c.Create_Date, Status = c.Status == 1 ? "Active" : "In Active", }).ToList(); //Sort if (Sort == "salaryDeductionAsc") { salaryDeductionList = salaryDeductionList.OrderBy(x => x.DeductionType).ToList(); } if (Sort == "salaryDeductionDesc") { salaryDeductionList = salaryDeductionList.OrderByDescending(x => x.DeductionType).ToList(); } if (Sort == "") { salaryDeductionList = salaryDeductionList.OrderByDescending(x => x.Create_Date).ToList(); } int RowCount = dataContext.SalaryDeduction_tbl.Count(); int tottCount = dataContext.SalaryDeduction_tbl.Count(); //Search if (!String.IsNullOrEmpty(Search)) { salaryDeductionList = salaryDeductionList .Where(s => s.DeductionType.ToLower().Contains(Search.ToLower())) .Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList(); } else { salaryDeductionList = salaryDeductionList.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList(); } int startnum = (PageIndex - 1) * PageSize + 1; int endnum = PageIndex * PageSize; RowCount = String.IsNullOrEmpty(Search) ? RowCount : salaryDeductionList.Count(); double lastpage = Math.Ceiling(Convert.ToDouble(RowCount) / Convert.ToDouble(PageSize)); paramList.Add(salaryDeductionList); listViewModel list_count = new listViewModel { RowCnt = RowCount, Start_Num = startnum, End_Num = endnum, TotCnt = tottCount, LastPage = lastpage }; paramList.Add(list_count); return(Json(paramList, JsonRequestBehavior.AllowGet)); } }
public JsonResult getEmployees(int PageIndex, int PageSize, string Search, string Sort) { using (PayRoll_Entities dataContext = new PayRoll_Entities()) { ArrayList paramList = new ArrayList(); var employeesList = dataContext.Employee_tbl.Select(c => new { c.id, c.Employee_Code, c.First_Name, c.Last_Name, Name = c.First_Name + " " + c.Last_Name, c.Designation, c.Mobile, Status = c.Status == 1 ? "Active" : "In Active", }).ToList(); //Sort if (Sort == "codeAsc") { employeesList = employeesList.OrderBy(x => x.Employee_Code).ToList(); } if (Sort == "codeDesc") { employeesList = employeesList.OrderByDescending(x => x.Employee_Code).ToList(); } if (Sort == "nameAsc") { employeesList = employeesList.OrderBy(x => x.First_Name).ToList(); } if (Sort == "nameDesc") { employeesList = employeesList.OrderByDescending(x => x.First_Name).ToList(); } if (Sort == "") { employeesList = employeesList.OrderByDescending(x => x.Employee_Code).ToList(); } int RowCount = dataContext.Employee_tbl.Count(); int tottCount = dataContext.Employee_tbl.Count(); //Search if (!String.IsNullOrEmpty(Search)) { employeesList = employeesList .Where(s => s.First_Name.ToLower().Contains(Search.ToLower()) || s.Employee_Code.ToLower().Contains(Search.ToLower())) .Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList(); } else { employeesList = employeesList.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList(); } int startnum = (PageIndex - 1) * PageSize + 1; int endnum = PageIndex * PageSize; RowCount = String.IsNullOrEmpty(Search) ? RowCount : employeesList.Count(); double lastpage = Math.Ceiling(Convert.ToDouble(RowCount) / Convert.ToDouble(PageSize)); paramList.Add(employeesList); listViewModel list_count = new listViewModel { RowCnt = RowCount, Start_Num = startnum, End_Num = endnum, TotCnt = tottCount, LastPage = lastpage }; paramList.Add(list_count); return(Json(paramList, JsonRequestBehavior.AllowGet)); } }