public ActionResult Index(string search, int pageNum = 0, int pageSize = 25) { NpgsqlCommand cmd; int temp = pageNum * pageSize; string queryString = "SELECT DISTINCT name " + "FROM actors " + Actor.OrderingString() + " limit " + pageSize.ToString() + " offset " + temp.ToString(); if (!String.IsNullOrEmpty(search)) { search = search.Replace(' ', '%'); queryString = "SELECT DISTINCT name FROM " + "actors where lower(name) like lower( @0 ) " + Actor.OrderingString() + " limit " + pageSize.ToString() + " offset " + temp.ToString(); cmd = QueryHandler.query(queryString, "%" + search + "%"); } else { cmd = QueryHandler.query(queryString); } List <Actor> actors = new List <Actor>(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { Console.Write(reader.FieldCount); String name = reader.GetString(0); Actor actor = new Actor(name); actors.Add(actor); } } return(View(actors)); }
// GET: Movies public ActionResult Index(string search, int pageNum = 0, int pageSize = 25) { NpgsqlCommand cmd; int temp = pageNum * pageSize; string queryString = "SELECT title, release_year, running_time," + "id FROM movies " + Movie.OrderingString() + " limit " + pageSize.ToString() + " offset " + temp.ToString(); if (!String.IsNullOrEmpty(search)) { search = search.Replace(' ', '%'); queryString = "SELECT title, release_year, running_time, id FROM " + "movies where lower(title) like lower( @0 ) " + Movie.OrderingString() + " limit " + pageSize.ToString() + " offset " + temp.ToString(); cmd = QueryHandler.query(queryString, "%" + search + "%"); } else { cmd = QueryHandler.query(queryString); } Console.WriteLine(queryString); List <Movie> movies = new List <Movie>(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { Console.Write(reader.FieldCount); String title = reader.GetString(0); Int32 ry = reader.GetInt32(1); Int32 rt = reader.GetInt32(2); Int32 id = reader.GetInt32(3); Movie movie = new Movie(title, ry, rt, id); movies.Add(movie); } } return(View(movies)); }