public ActionResult school(int pageIndex = 1, int pageSize = 10, int?id = 0) { List <newstype> typelist = new List <newstype>(); string whereS = " PPID=2 and del =1"; typelist = newstypeBLL.GetAll(whereS); ViewBag.data = typelist; List <newst> list = new List <newst>(); List <newsName> li = new List <newsName>(); ViewData["pageIndex"] = pageIndex; ViewData["pageSize"] = pageSize; ViewData["total"] = 0; ViewData["name"] = newstypeBLL.GetById((int)id).typename; int totalcount = 0; StringBuilder where = new StringBuilder(); where.Append(" and del =1 and newstype = " + id); SortParameter sa = new SortParameter(); sa.Field = "creationtime"; sa.Direction = SortDirection.DESC; SortParameters ot = new SortParameters(); ot.Add(sa); list = newsbll.GetPage(out totalcount, pageIndex, pageSize, where.ToString(), "", ot); // list = newsbll.getall(); ViewData["total"] = totalcount; if (list.Count > 0) { foreach (var item in list) { newsName model = new newsName(); model.id = item.id; model.headline = item.headline; model.newstype = item.newstype; model.newstypename = newstypeBLL.GetById((int)item.newstype).typename; model.userid = item.userid; model.del = item.del; model.creationtime = item.creationtime; model.contenttext = item.contenttext; li.Add(model); } } return(View(li)); }
public ActionResult newsList(int pageIndex = 1, int pageSize = 10) { List <newst> list = new List <newst>(); List <newsName> li = new List <newsName>(); ViewData["pageIndex"] = pageIndex; ViewData["pageSize"] = pageSize; ViewData["total"] = 0; try { string name = Request["name"]; string start = Request["start"]; string end = Request["end"]; int totalcount = 0; StringBuilder where = new StringBuilder(); where.Append(" and del =1 "); if (!string.IsNullOrWhiteSpace(name)) { where.Append(" and headline like'%" + name.Trim() + "%'"); } if (!string.IsNullOrWhiteSpace(start) && !string.IsNullOrWhiteSpace(end)) { //where.Append(" and creationtime>='" + start + "'"); //creationtime between '2016-12-07' and '2016-12-08 23:59:59' where.Append(" and creationtime between '" + start + "' and '" + end + " 23:59:59'"); } if (!string.IsNullOrWhiteSpace(start) && string.IsNullOrWhiteSpace(end)) { where.Append(" and creationtime>='" + start + "'"); } if (string.IsNullOrWhiteSpace(start) && !string.IsNullOrWhiteSpace(end)) { where.Append(" and creationtime<='" + end + " 23:59:59'"); } SortParameter sa = new SortParameter(); sa.Field = "creationtime"; sa.Direction = SortDirection.DESC; SortParameters ot = new SortParameters(); ot.Add(sa); list = newsbll.GetPage(out totalcount, pageIndex, pageSize, where.ToString(), "", ot); // list = newsbll.getall(); ViewData["total"] = totalcount; if (list.Count > 0) { foreach (var item in list) { newsName model = new newsName(); model.id = item.id; model.headline = item.headline; model.newstype = item.newstype; model.newstypename = newstypeBLL.GetById((int)item.newstype).typename; model.userid = item.userid; model.del = item.del; model.creationtime = item.creationtime; model.contenttext = item.contenttext; li.Add(model); } } } catch (Exception) { } return(View(li)); }