/// <summary> /// 获取Item的内容及回复等信息 /// </summary> /// <param name="id"></param> /// <returns></returns> public BBSItemListViewData GetItemDetailInfoByID(int id) { BBSItemListViewData BBSItemViewData = new BBSItemListViewData(); try { // 根据BBSItem的ID取出该条BBSItem的内容 //BBSItemViewData.BBSItem = (from bi in CQGJ.BBSItem where bi.ItemID == id select bi).First(); // 获取发起帖的内容 BBSItemViewData.TopicItemInfo = new BBSItemInfo { TopicBBSItem = (from bi in CQGJ.BBSItem where bi.ItemID == id select bi).First()}; // 获取发起帖作者的信息 BBSItemViewData.TopicItemInfo.Author = GetUserInfoByID((int)BBSItemViewData.TopicItemInfo.TopicBBSItem.UserReference.EntityKey.EntityKeyValues[0].Value); try { // 根据ParentID取出对该条BBSItem的回帖内容 BBSItemViewData.BBSItemsList = (from bj in CQGJ.BBSItem where bj.ParentID == id select bj).ToList(); // 获取该条BBS所属的BBS的ID BBSItemViewData.BBSID = (int)BBSItemViewData.TopicItemInfo.TopicBBSItem.BBSReference.EntityKey.EntityKeyValues[0].Value; // 获取回帖信息及回帖作者信息 BBSItemViewData.BBSItemInfo = new List<BBSItemInfo>(); foreach (BBSItem bi in BBSItemViewData.BBSItemsList) { BBSItemInfo tempInfo = new BBSItemInfo { TopicBBSItem = bi, Author = GetUserInfoByID((int)bi.UserReference.EntityKey.EntityKeyValues[0].Value) }; BBSItemViewData.BBSItemInfo.Add(tempInfo); } } catch (ArgumentNullException) { Response.Write("没有回帖"); } } catch (ArgumentNullException) { Response.Write("该帖已被删除"); } catch(Exception ex) { Response.Write(ex.Message); } return BBSItemViewData; }
/// <summary> /// 根据BBS标题关键字获取BBSItem /// </summary> /// <param name="id"></param> /// <param name="title"></param> /// <returns></returns> public BBSItemListViewData GetBBSItemsByTitle(int id, string title) { BBSItemListViewData ItemListVD = new BBSItemListViewData(); ItemListVD.BBSID = id; ItemListVD.BBSInfo = (from b in CQGJ.BBS where b.BBSID == id select b).First(); ItemListVD.BBSItemInfo = new List<BBSItemInfo>(); var searchedItems = from bi in CQGJ.BBSItem where bi.BBS.BBSID == id && bi.ParentID == -1 && bi.Subject.Contains(title) select bi; foreach (var a in searchedItems) { BBSItemInfo temp = new BBSItemInfo(); temp.TopicBBSItem = new BBSItem(); temp.TopicBBSItem = a; ItemListVD.BBSItemInfo.Add(temp); } return ItemListVD; }
/// <summary> /// 根据用户ID获取其所有发帖 /// </summary> /// <param name="id">Passport数据库中的用户ID</param> /// <returns>用户发帖信息</returns> public BBSItemListViewData ListBBSItemsByUserID(int id) { // 将Passport数据库中的用户ID转化为CQGJ数据库中的用户ID int userId = ToUserID(id); // 定义BBSItemViewData用来保存ID为id用户所发出的帖子列表 BBSItemListViewData BBSItemViewData = new BBSItemListViewData(); BBSItemViewData.UserID = userId; int bbsId = GetCurrentBBSID(); try { // 根据用户ID以及ParentID=-1来取出该用户所发的帖子, 并以列表的方式保存. b 为临时变量 var b = from bi in CQGJ.BBSItem where bi.User.UserID == userId && bi.ParentID == -1 && bi.BBS.BBSID == bbsId select bi; BBSItemViewData.BBSItemInfo = new List<BBSItemInfo>(); foreach (var temp in b) { // 初使化信息参数 BBSItemInfo tempInfo = new BBSItemInfo(); tempInfo.LastReply = new BBSItem(); tempInfo.TopicBBSItem = new BBSItem(); // 填充BBSItem信息 tempInfo.TopicBBSItem = temp; // 发起帖 var tempLastReply = from bi in CQGJ.BBSItem where bi.ParentID == temp.ItemID orderby bi.SubmitTime descending select bi; if (tempLastReply.Count() > 0) { tempInfo.LastReply = tempLastReply.First(); // 最新回复帖 } BBSItemViewData.BBSItemInfo.Add(tempInfo); } return BBSItemViewData; } catch (ArgumentNullException) { return null; } }
/// <summary> /// 根据BBS论坛ID以前ParentID=-1来分页显示BBS论坛的所有Topic /// </summary> /// <param name="id">该论坛的ID</param> public void ListBBSItemsByPage(int id, int page) { // 定义BBSItemViewData用来保存BBS Topic的列表 BBSItemListViewData BBSItemViewData = new BBSItemListViewData(); BBSItemViewData.BBSID = id; HttpContext.Session["CurrentBBSID"] = id; // count 保存item的总条数 int count = 0; try { // 获取该BBS的相关信息 BBSItemViewData.BBSInfo = (from b in CQGJ.BBS where b.BBSID == id select b).FirstOrDefault(); // 获取当前用户信息 BBSItemViewData.User = (CQGJ.passport.User)HttpContext.Session["userobject"]; // 根据BBS论坛ID以前ParentID=-1来取出该BBS论坛的所有Topic, 并以列表的方式保存 var a = from bi in CQGJ.BBSItem where bi.BBS.BBSID == id && bi.ParentID == -1 select bi; // item的总条数 count = a.Count(); BBSItemViewData.BBSItemInfo = new List<BBSItemInfo>(); foreach (var temp in a) { // 初使化信息参数 BBSItemInfo tempInfo = new BBSItemInfo(); tempInfo.LastReply = new BBSItem(); tempInfo.TopicBBSItem = new BBSItem(); // 填充BBSItem信息 tempInfo.TopicBBSItem = temp; // 发起帖 var tempLastReply = from bi in CQGJ.BBSItem where bi.ParentID == temp.ItemID orderby bi.SubmitTime descending select bi; if (tempLastReply.Count() > 0) { tempInfo.LastReply = tempLastReply.First(); // 最新回复帖 } BBSItemViewData.BBSItemInfo.Add(tempInfo); } List<BBSItemInfo> itemList = new List<BBSItemInfo>(); foreach (var b in BBSItemViewData.BBSItemInfo) { BBSItem topic = b.TopicBBSItem; BBSItem lastReply = b.LastReply; BBSItemInfo info = new BBSItemInfo { LastReply = lastReply, TopicBBSItem = topic }; itemList.Add(info); } BBSItemViewData.BBSItemInfo.Clear(); BBSItemViewData.BBSItemInfo = itemList.Skip(10 * (page - 1)).Take(10).ToList(); // 定义分页信息 UrlManager urlManager = new DefaultUrlManager(count, 10); Pager pager = new Pager(urlManager); BBSItemViewData.PagerString = pager.PagerString; } catch (ArgumentNullException) { Response.Write("该班级还没有人发贴!"); } RenderView("ListBBSItems", BBSItemViewData); }
/// <summary> /// 根据BBS论坛ID以前ParentID=-1来取出该BBS论坛的所有Topic /// </summary> /// <param name="id">该论坛的ID</param> public BBSItemListViewData ListBBSItemsByBBSID(int id) { // 定义BBSItemViewData用来保存BBS Topic的列表 BBSItemListViewData BBSItemViewData = new BBSItemListViewData(); BBSItemViewData.BBSID = id; try { // 获取该BBS的相关信息 BBSItemViewData.BBSInfo = (from b in CQGJ.BBS where b.BBSID == id select b).First(); // 根据BBS论坛ID以前ParentID=-1来取出该BBS论坛的所有Topic, 并以列表的方式保存 var a = from bi in CQGJ.BBSItem where bi.BBS.BBSID == id && bi.ParentID == -1 select bi; BBSItemViewData.BBSItemInfo = new List<BBSItemInfo>(); foreach (var temp in a) { // 初使化信息参数 BBSItemInfo tempInfo = new BBSItemInfo(); tempInfo.LastReply = new BBSItem(); tempInfo.TopicBBSItem = new BBSItem(); // 填充BBSItem信息 tempInfo.TopicBBSItem = temp; // 发起帖 var tempLastReply = from bi in CQGJ.BBSItem where bi.ParentID == temp.ItemID orderby bi.SubmitTime descending select bi; if (tempLastReply.Count() > 0) { tempInfo.LastReply = tempLastReply.First(); // 最新回复帖 } BBSItemViewData.BBSItemInfo.Add(tempInfo); } return BBSItemViewData; } catch (ArgumentNullException) { return null; } }
/// <summary> /// 根据BBS论坛ID以前ParentID=-1来取出该BBS论坛的所有Topic /// </summary> /// <param name="id">该论坛的ID</param> public void ListBBSItems(int id) { // 定义BBSItemViewData用来保存BBS Topic的列表 BBSItemListViewData BBSItemViewData = new BBSItemListViewData(); BBSItemViewData.BBSID = id; HttpContext.Session["CurrentBBSID"] = id; try { BBSItemViewData.BBSInfo = (from b in CQGJ.BBS where b.BBSID == id select b).First(); BBSItemViewData.User = (CQGJ.passport.User)HttpContext.Session["userobject"]; // 根据BBS论坛ID以前ParentID=-1来取出该BBS论坛的所有Topic, 并以列表的方式保存 var a = from bi in CQGJ.BBSItem where bi.BBS.BBSID == id && bi.ParentID == -1 select bi; BBSItemViewData.BBSItemInfo = new List<BBSItemInfo>(); foreach (var temp in a) { // 初使化信息参数 BBSItemInfo tempInfo = new BBSItemInfo(); tempInfo.LastReply = new BBSItem(); tempInfo.TopicBBSItem = new BBSItem(); // 填充BBSItem信息 tempInfo.TopicBBSItem = temp; // 发起帖 var tempLastReply = from bi in CQGJ.BBSItem where bi.ParentID == temp.ItemID orderby bi.SubmitTime descending select bi; if (tempLastReply.Count() > 0) { tempInfo.LastReply = tempLastReply.First(); // 最新回复帖 } BBSItemViewData.BBSItemInfo.Add(tempInfo); } RenderView("ListBBSItems", BBSItemViewData); } catch (ArgumentNullException) { Response.Write("该班级还没有人发贴!"); } }