public JsonResult PaginationResult(jsonstudent ss) { Result r = new Result(); int perpage = ss.perpage; try { using (StudentsEntities se = new StudentsEntities()) { var students = se.newstudents.Where(s => s.first_name.Contains(ss.first_name) && s.last_name.Contains(ss.last_name) && s.email.Contains(ss.email) && s.rollnumber.Contains(ss.rollnumber) ).ToList(); foreach (var item in ss.range) { students = students.Where(s => item.min <= (int)s[item.field] && (int)s[item.field] <= item.max).ToList(); } foreach (var item in ss.selectables) { if(item.value != null) students = students.Where(s => item.value.Any(x => x == s[item.key].ToString())).ToList(); } r.status = 1; if ((ss.pageno - 1) * ss.perpage + ss.perpage > students.Count) perpage = students.Count - (ss.pageno - 1) * ss.perpage; r.data = students.GetRange((ss.pageno - 1) * ss.perpage, perpage); if (ss.orderBy != null) { if (ss.orderType.ToLower() == "asc") r.data = students.GetRange((ss.pageno - 1) * ss.perpage, perpage).OrderBy(s => s[ss.orderBy]); else r.data = students.GetRange((ss.pageno - 1) * ss.perpage, perpage).OrderByDescending(s => s[ss.orderBy]); } } } catch(Exception e) { r.data = ""; r.error = e.Message; r.status = 0; } return Json(r); }
public JsonResult SearchResult(jsonstudent ss) { Result r = new Result(); try { using (StudentsEntities se = new StudentsEntities()) { var students = se.newstudents.Where(s => s.first_name.Contains(ss.first_name) && s.last_name.Contains(ss.last_name) && s.email.Contains(ss.email) && s.rollnumber.Contains(ss.rollnumber) ).ToList(); if (ss.israngeChanged) { foreach (var item in ss.range) { students = students.Where(s => item.min <= (int)s[item.field] && (int)s[item.field] <= item.max).ToList(); } } if (ss.isselectionChanged) { foreach (var item in ss.selectables) { if (item.value != null) students = students.Where(s => item.value.Any(x => x == s[item.key].ToString())).ToList(); } } outputResult o = new outputResult(); o.count = students.Count(); if (!ss.isselectionChanged) { foreach (var item in ss.selectables) { var tempdata = students.GroupBy(s => s[item.key]).Select(g => new{ key = g.Key, count = g.Count() } ).ToList().Distinct().ToList(); List<string[]> sampledata = new List<string[]>(); foreach (var temp in tempdata) { string[] tempArray = new string[2]; tempArray[0] = temp.key.ToString(); tempArray[1] = temp.count.ToString(); sampledata.Add(tempArray); } o.selectables.Add(item.key, sampledata); } } foreach (var item in ss.range) { o.range.Add(new Range { field = item.field, min = (int)students.Min(s => s[item.field]), max = (int)students.Max(s => s[item.field]) }); } r.status = 1; r.data = o; } } catch (Exception e) { r.data = ""; r.error = e.Message; r.status = 0; } return Json(r); }