// GET: Stars public ActionResult Index(int?page) { newslist nl = new newslist(); nl.ctLst = new List <ContentModel>(); string sql = @"select a.news_id, a.title, a.description, a.image, b.category_name from news a join category b on a.cat_id = b.category_id where category_id = 4"; connection.Open(); int count = 0; try { cmd.Connection = connection; cmd.CommandText = sql; using (DbDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { ++count; ContentModel cm = new ContentModel(); cm.news_id = Convert.ToInt64(reader.GetValue(0)); cm.title = reader.GetString(1); cm.descp = reader.GetString(2); try { cm.imageLnk = reader.GetString(3); } catch (Exception ex) { cm.imageLnk = ""; } cm.cat_name = reader.GetString(4); cm.Stt = count; //cm.category_id = Convert.ToInt64(reader.GetValue(0)); nl.ctLst.Add(cm); } } } } catch (Exception e) { Console.WriteLine("Error: " + sql); Console.WriteLine(e.StackTrace); } finally { connection.Close(); //connection.Dispose(); //connection = null; } int pageSize = 10; int pageNumber = (page ?? 1); return(View(nl.ctLst.ToPagedList(pageNumber, pageSize))); }
// GET: France public ActionResult Index(int?page) { string json = string.Empty; string JsonText = FlagsConst.newsJs + "france"; using (WebClient wc = new WebClient()) { wc.Headers["Content-Type"] = "application/json;charset=UTF-8"; json = wc.DownloadString(JsonText); } newslist nl = new newslist(); nl.ctLst = new List <ContentModel>(); int count = 0; LatData objGo = JsonConvert.DeserializeObject <LatData>(json); foreach (var x in objGo.data) { ++count; ContentModel cm = new ContentModel(); cm.title = x.title; cm.descp = x.description; cm.hot = 0; cm.imageLnk = x.image; cm.origin_url = x.link; cm.source = x.siteName; cm.Stt = count; nl.ctLst.Add(cm); } int pageSize = 10; int pageNumber = (page ?? 1); return(View(nl.ctLst.ToPagedList(pageNumber, pageSize))); }
public ActionResult Search(int?page) { var tmp = TempData["page"]; if (tmp != null) { page = (int)TempData["page"]; } newslist nl = new newslist(); nl.ctLst = new List <ContentModel>(); string sql = @"select a.title, a.description, b.category_name, a.news_id, a.origin_url from news a join category b on a.cat_id = b.category_id order by news_id desc"; connection.Open(); try { cmd.Connection = connection; cmd.CommandText = sql; using (DbDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { ContentModel cm = new ContentModel(); cm.title = reader.GetString(0); cm.descp = reader.GetString(1); cm.cat_name = reader.GetString(2); cm.news_id = Int64.Parse(reader.GetString(3)); if (reader.GetString(4) != null || reader.GetString(4) != "") { cm.origin_url = reader.GetString(4); } //cm.category_id = Convert.ToInt64(reader.GetValue(0)); nl.ctLst.Add(cm); } } } } catch (Exception e) { Console.WriteLine("Error: " + sql); Console.WriteLine(e.StackTrace); } finally { connection.Close(); //connection.Dispose(); //connection = null; } int pageSize = 10; int pageNumber = (page ?? 1); return(PartialView("_NewsLst", nl.ctLst.ToPagedList(pageNumber, pageSize))); }
// GET: DataWh public ActionResult Index(int?page) { getCate(); newslist nl = new newslist(); nl.ctLst = new List <ContentModel>(); string sql = @"select a.title, a.description, b.category_name, a.news_id, a.origin_url from news a left join category b on a.cat_id = b.category_id where a.cat_id = -1"; if (connection.State != ConnectionState.Open) { connection.Open(); } try { cmd.Connection = connection; cmd.CommandText = sql; using (DbDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { ContentModel cm = new ContentModel(); cm.title = reader.GetString(0); cm.descp = reader.GetString(1); //cm.cat_name = reader.GetString(2); cm.news_id = Int64.Parse(reader.GetString(3)); cm.origin_url = reader.GetString(4); cm.catList = new List <Category>(); cm.catList = lstCa; //cm.category_id = Convert.ToInt64(reader.GetValue(0)); nl.ctLst.Add(cm); } } } } catch (Exception e) { Console.WriteLine("Error: " + sql); Console.WriteLine(e.StackTrace); } finally { connection.Close(); //connection.Dispose(); //connection = null; } int pageSize = 10; int pageNumber = (page ?? 1); return(View(nl.ctLst.ToPagedList(pageNumber, pageSize))); }
public ActionResult SearchBoard() { newslist nl = new newslist(); nl.ctLst = new List <ContentModel>(); string sql = @"select a.news_id, a.title, a.description, a.image, b.category_name from news a join category b on a.cat_id = b.category_id order by a.news_id desc limit 10 "; connection.Open(); int count = 0; try { cmd.Connection = connection; cmd.CommandText = sql; using (DbDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { ++count; ContentModel cm = new ContentModel(); cm.news_id = Convert.ToInt64(reader.GetValue(0)); cm.title = reader.GetString(1); cm.descp = reader.GetString(2); try { cm.imageLnk = reader.GetString(3); } catch (Exception ex) { cm.imageLnk = ""; } cm.cat_name = reader.GetString(4); cm.Stt = count; //cm.category_id = Convert.ToInt64(reader.GetValue(0)); nl.ctLst.Add(cm); } } } } catch (Exception e) { Console.WriteLine("Error: " + sql); Console.WriteLine(e.StackTrace); } return(PartialView("_NewsBoard", nl)); }