// GET: /City/ public ActionResult Index(string sortOrder, string searchString, string currentFilter, int?page) { ViewBag.CurrentSort = sortOrder; ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; ViewBag.CurrentFilter = searchString; User LoggedInUser = HttpContext.Session["LoggedUser"] as User; QueryBuilder qb = new QueryBuilder(); string query = qb.QueryForUserAccess(LoggedInUser, "City"); System.Data.DataTable dt = qb.GetValuesfromDB("Select * FROM City where " + query); var cities = dt.ToList <City>().AsQueryable(); if (!String.IsNullOrEmpty(searchString)) { cities = cities.Where(s => s.CityName.ToUpper().Contains(searchString.ToUpper()) || s.CityName.ToUpper().Contains(searchString.ToUpper())); } switch (sortOrder) { case "name_desc": cities = cities.OrderByDescending(s => s.CityName); break; default: cities = cities.OrderBy(s => s.CityName); break; } int pageSize = 8; int pageNumber = (page ?? 1); return(View(cities.ToPagedList(pageNumber, pageSize))); //return View(cities.ToList()); }
public PagedUserArgs <UserInfo> List(PagedUserArgs <UserInfo> query) { if (query == null) { query = new PagedUserArgs <UserInfo>(); } var db = this.GetDatabase(); IQueryable <UserInfo> rs = this.GetQueryable(query, db.UserInfo); query.ResultCount = rs.Count(); rs = rs.OrderByDescending(item => item.Id); if (query.PageIndex > 0 && query.PageSize > 0) { rs = rs.Skip((query.PageIndex - 1) * query.PageSize).Take(query.PageSize); } query.Results = rs.ToArray(); var dataTable = new System.Data.DataTable(); dataTable.Columns.Add("Id", Int64.MinValue.GetType()); dataTable.Columns.Add("Name", string.Empty.GetType()); dataTable.Columns.Add("FullName", string.Empty.GetType()); foreach (var data in query.Results) { var dataRow = dataTable.NewRow(); dataRow["Id"] = data.Id; dataRow["Name"] = data.Name; dataRow["FullName"] = data.FullName; dataTable.Rows.Add(dataRow); } var array = dataTable.ToArray <UserInfo>(); var list = dataTable.ToList <UserInfo>(); return(query); }