// for testing public void toTest() { BBSListViewData bvd = new BBSListViewData(); Classes d = (from b in CQGJ.BBS where b.BBSID == 1 select b.Classes).First(); //bvd.BBSList = (from c in CQGJ.Classes // join b in CQGJ.BBS on c.ClassID equals b.Classes.ClassID // select b).ToList(); //bvd.BBSList = (from b in CQGJ.BBS // join c in CQGJ.Classes on b.Classes.ClassID equals c.ClassID // select b).ToList(); bvd.BBSList = (from b in CQGJ.BBS join c in CQGJ.Classes on b.Classes.ClassID equals c.ClassID where c.ClassID == (from s in CQGJ.Student where s.User.UserID == 1 select s.User.UserID).FirstOrDefault() select b).ToList(); passport.CQGJPassport pqgj = new CQGJ.passport.CQGJPassport(); bvd.User = pqgj.GetCQGJUser(1); int i = bvd.User.UserID; RenderView("test", bvd); }
/// <summary> /// 显示出所有的BBS /// </summary> public void ListBBS() { // 定义BBS列表BBSListViewData,用于保存从数据库中读取到的所有的BBS BBSListViewData BBSListViewData = new BBSListViewData(); try { // 从数据库中读取到的所有的BBS BBSListViewData.BBSList = (from bbsList in CQGJ.BBS select bbsList).ToList(); // 取出本论坛最新贴子 //BBSListViewData.LastBBSItem = (from bbsItem in CQGJ.BBSItem //orderby bbsItem.SubmitTime select bbsItem).First(); BBSListViewData.BBSInfo = new List<BBSInfo>(); foreach (var a in BBSListViewData.BBSList) { // 初始化参数 BBSInfo tempInfo = new BBSInfo(); tempInfo.BBS = new BBS(); tempInfo.BBSItemsNbr = 0; tempInfo.LastBBSItem = new BBSItem(); tempInfo.OwnerName = "no one"; // 查询赋值 tempInfo.BBS = a; var tempBBSItem = from bi in CQGJ.BBSItem where bi.BBS.BBSID == a.BBSID orderby bi.SubmitTime descending select bi; if (tempBBSItem.Count() > 0) { tempInfo.LastBBSItem = (from bi in CQGJ.BBSItem where bi.BBS.BBSID == a.BBSID orderby bi.SubmitTime descending select bi).First(); } tempInfo.BBSItemsNbr = (from bi in CQGJ.BBSItem where bi.BBS.BBSID == a.BBSID select bi).Count(); BBSListViewData.BBSInfo.Add(tempInfo); } // 将BBS列表以BBSListViewData对象的形式绑定到ListBBS.aspx页面 RenderView("ListBBS", BBSListViewData); } catch (ArgumentNullException) { Response.Write("目前不存在BBS论坛!"); } }
/// <summary> /// 从数据库中删除一个班级BBS论坛 /// </summary> /// <param name="bbsID">被删除的BBS的ID</param> public void RemoveBBS(int id) { BBS bbs = new BBS(); try { bbs = (from b in CQGJ.BBS where b.BBSID == id select b).First(); CQGJ.DeleteObject(bbs); CQGJ.SaveChanges(); // 定义BBS列表BBSListViewData,用于保存从数据库中读取到的所有的BBS BBSListViewData BBSListViewData = new BBSListViewData(); // 从数据库中读取到的所有的BBS BBSListViewData.BBSList = (from bbsList in CQGJ.BBS select bbsList).ToList(); // 将BBS列表以BBSListViewData对象的形式绑定到ListBBS.aspx页面 RenderView("ListBBS", BBSListViewData); } catch (ArgumentNullException) { //Response.Write(nullException.ToString()); Response.Write("</br>该记录已删除!"); } catch (InvalidOperationException) { //Response.Write(invalidOperationException.ToString()); Response.Write("</br>该记录已删除!"); } }
// for testing public ActionResult toTest() { BBSListViewData bvd = new BBSListViewData(); Classes d = (from b in CQGJ.BBS where b.BBSID == 1 select b.Classes).First(); //bvd.BBSList = (from c in CQGJ.Classes // join b in CQGJ.BBS on c.ClassID equals b.Classes.ClassID // select b).ToList(); //bvd.BBSList = (from b in CQGJ.BBS // join c in CQGJ.Classes on b.Classes.ClassID equals c.ClassID // select b).ToList(); bvd.BBSList = (from b in CQGJ.BBS join c in CQGJ.Classes on b.Classes.ClassID equals c.ClassID where c.ClassID == (from s in CQGJ.Student where s.User.UserID == 1 select s.User.UserID).FirstOrDefault() select b).ToList(); User user = (from u in CQGJ.User where u.UserID == 1 select u).First(); bvd.User = user; int i = bvd.User.UserID; return View("test", bvd); }