public ActionResult AddFromTopic(FormCollection f) { try { string title = f["title"]; string content = f["content"]; string username = f["username"]; string fid = f["fid"]; string tid1 = f["tid"]; string picurl = f["picurl"]; string anony = f["anony"]; string uid = f["uid"]; if (title == null) { #region 添加评论/楼数 Miaow.DataSys.sns_Post post = Miaow.DataClass.jz.Querys.IrainDb.sns_Post.CreateObject(); if (anony == "" || anony == null) { post.author = Miaow.function.StringHelper.GetRealIP(); } else { post.author = anony; } //更新回复主表 post.fid = Convert.ToInt32(fid); post.authorico = 0; post.authorid = 0; post.guestname = 0; post.subject = ""; post.dateline = Miaow.function.DateHelper.GetNowToMysqlTime(); post.up = 0; post.wave = 0; post.down = 0; post.postip = Miaow.function.StringHelper.GetRealIP(); post.tid = Convert.ToInt32(tid1); post.replyfloor = (short)(Miaow.DataClass.jz.Querys.GetPostMaxFloorByTid(post.tid) + 1); Miaow.DataClass.jz.Querys.IrainDb.sns_Post.AddObject(post); //更新回复详细表 Miaow.DataSys.sns_PostContent postContent = Miaow.DataClass.jz.Querys.IrainDb.sns_PostContent.CreateObject(); postContent.message = content + "<br/>" + picurl; postContent.picture = ""; postContent.tid = Convert.ToInt32(tid1); Miaow.DataClass.jz.Querys.IrainDb.sns_PostContent.AddObject(postContent); //更新楼数 最后一个回复人id username Miaow.DataSys.sns_topic toppic = Miaow.DataClass.jz.Querys.GetSingleTopPicByTid(post.tid); toppic.replies += 1; toppic.lastauthor = Miaow.function.StringHelper.GetAnonyIP(); toppic.lastauthorid = 0; int res = Miaow.DataClass.jz.Querys.IrainDb.SaveChanges(); //更新新鲜事儿首页会显示这些信息的 Miaow.DataSys.sns_feed_template tmeplate = Miaow.DataClass.jz.Querys.GetSingleFeedTemplateByType("forum_reply"); Miaow.DataSys.sns_feed feed = Miaow.DataClass.jz.Querys.IrainDb.sns_feed.CreateObject(); //这个地方得改改,不过现在,还不晓得怎么改的 feed.appid = "0"; feed.feedtype = 0; feed.fid = 0; feed.type = "forum_reply"; feed.cTime = (int?)post.dateline; feed.uid = 0; feed.username = Miaow.function.StringHelper.GetAnonyIP(); feed.title_data = feed.username + "回复了主题帖:<a href='/topic/" + post.tid + "/x' target='_blank'>" + toppic.subject + "</a>"; feed.body_data = feed.title_data; Webdiyer.WebControls.Mvc.PagedList<Miaow.DataClass.jz.SinglePostDetail> model = null; model = Miaow.DataClass.jz.Querys.GetTopPicPostDetailListById(post.tid, 1, pageSize, "last"); return PartialView("ListTopicPartital", model); #endregion } else { #region 添加新帖子 sns_topic toppic = new sns_topic(); sns_Post post = new sns_Post(); sns_PostContent postContent = new sns_PostContent(); postContent.isHtml = 0; if (picurl == null) { postContent.message = content; } else { postContent.message = content + "<br/>" + picurl; } postContent.picture = ""; if (username == null) { post.author = Miaow.function.StringHelper.GetRealIP(); toppic.author = Miaow.function.StringHelper.GetRealIP(); toppic.lastauthor = Miaow.function.StringHelper.GetRealIP(); } else { post.author = username; toppic.author = username; toppic.lastauthor = username; } post.fid = Convert.ToInt32(fid); post.authorico = 0; post.authorid = 0; post.subject = title; post.dateline = Miaow.function.DateHelper.GetNowToMysqlTime(); post.up = 0; post.wave = 0; post.postip = Miaow.function.StringHelper.GetRealIP(); post.replyfloor = 0; toppic.dateline = Miaow.function.DateHelper.GetNowToMysqlTime(); toppic.lasttime = Miaow.function.DateHelper.GetNowToMysqlTime(); toppic.fid = Convert.ToInt32(fid); toppic.authorico = 0; toppic.authorid = 0; toppic.lastauthorid = 0; toppic.subject = title; Miaow.DataClass.jz.Querys.IrainDb.sns_topic.AddObject(toppic); int res = Miaow.DataClass.jz.Querys.IrainDb.SaveChanges(); if(res > 0 ) { sns_topic topic = Miaow.DataClass.jz.Querys.GetSingleTopPicBySubject(title); int tid = topic.tid; post.tid = tid; postContent.tid = tid; Miaow.DataClass.jz.Querys.IrainDb.sns_Post.AddObject(post); Miaow.DataClass.jz.Querys.IrainDb.sns_PostContent.AddObject(postContent); Miaow.DataClass.jz.Querys.IrainDb.SaveChanges(); } return RedirectToAction("ListTopic", "Forum", new { tid = post.tid, num = "", pageIndex = 1 }); ////获得活动的名称 //string title1 = FroumModels.irainbow.sns_forum.Where(o => o.fid == post.fid).SingleOrDefault().name; //ViewBag.Name = title; //return PartialView("ForumListTopicC", new FroumModels(post.fid, title1, null, 60)); #endregion } } catch (Exception ex) { throw; } }
/// <summary> /// 获得帖子详情 /// </summary> /// <param name="tid">The tid.</param> /// <param name="pageIndex">Index of the page.</param> /// <param name="pageSize">Size of the page.</param> public void InitForumTopic(int? tid, int? pageIndex, int? pageSize) { try { IsLogin(); GropuDic(); this.PostContentList = irainbow.sns_PostContent.Where(o => o.tid == tid).OrderBy(o => o.pid).ToPagedList(pageIndex ?? 1, pageSize ?? 15); //贴子数据 this.sns_topic = irainbow.sns_topic.Where(o => o.tid == tid).SingleOrDefault(); //回复数 replayNum = irainbow.sns_topic.Where(o => o.tid == tid).Count(); this.sns_forum = irainbow.sns_forum.Where(o => o.fid == this.sns_topic.fid).SingleOrDefault(); this.CurrenCatalog = irainbow.sns_forum_catalog.Where(o => o.cid == sns_forum.cid).SingleOrDefault(); //this.postList = irainbow.sns_Post.Where(o => o.tid == tid).SingleOrDefault(); this.forumPostList = irainbow.sns_Post.Where(o => o.tid == tid).OrderBy(o => o.pid).ToPagedList(pageIndex ?? 1, pageSize ?? 15); //this.forumTopicList = irainbow.sns_topic.Where(o => o.authorico == sns_topic.authorico).ToPagedList(pageIndex ?? 1, 5); this.forumSuiTopicList = new List<sns_topic>(); List<sns_Post> list = irainbow.sns_Post.Where(o => o.authorid == sns_topic.authorid).ToList(); //var temp = irainbow.sns_Post.Where(o => o.authorid == list[i].authorid).Count(); for (int i = 0; i < list.Count; i++) { var r = new Random(); if (list.Count > 0) { if (forumSuiTopicList.Count <= 5) { //产生一个随机数 var ToSkip = r.Next(0, list.Count); int a = list[i].authorid; DataSys.sns_topic tempPic = irainbow.sns_topic.Where(o => o.authorid == a).OrderBy(o => o.fid).Skip(ToSkip).Take(1).FirstOrDefault(); // tempPic.r //(from e in irainbow.sns_Post where e.authorid == list[i].authorid orderby e.pid select e).Skip(ToSkip).Take(1).FirstOrDefault(); if (tempPic != null) { //判断是否已存在集合中 if (!forumSuiTopicList.Contains(tempPic)) { forumSuiTopicList.Add(tempPic); } } } else { break; } } } sns_topic.views = sns_topic.views + 1;//查看帖子加一 // irainbow.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public ActionResult AddFromTopic(FormCollection f) { try { string title = f["title"]; string content = f["content"]; string username = f["username"]; string fid = f["fid"]; string tid1 = f["tid"]; string picurl = f["picurl"]; string anony = f["anony"]; string uid = f["uid"]; if (title == null) { #region 添加评论/楼数 iPow.DataSys.sns_Post post = iPow.DataClass.jz.Querys.IrainDb.sns_Post.CreateObject(); if (anony == "" || anony == null) { post.author = iPow.function.StringHelper.GetRealIP(); } else { post.author = anony; } //更新回复主表 post.fid = Convert.ToInt32(fid); post.authorico = 0; post.authorid = 0; post.guestname = 0; post.subject = ""; post.dateline = iPow.function.DateHelper.GetNowToMysqlTime(); post.up = 0; post.wave = 0; post.down = 0; post.postip = iPow.function.StringHelper.GetRealIP(); post.tid = Convert.ToInt32(tid1); post.replyfloor = (short)(iPow.DataClass.jz.Querys.GetPostMaxFloorByTid(post.tid) + 1); iPow.DataClass.jz.Querys.IrainDb.sns_Post.AddObject(post); //更新回复详细表 iPow.DataSys.sns_PostContent postContent = iPow.DataClass.jz.Querys.IrainDb.sns_PostContent.CreateObject(); postContent.message = content + "<br/>" + picurl; postContent.picture = ""; postContent.tid = Convert.ToInt32(tid1); iPow.DataClass.jz.Querys.IrainDb.sns_PostContent.AddObject(postContent); //更新楼数 最后一个回复人id username iPow.DataSys.sns_topic toppic = iPow.DataClass.jz.Querys.GetSingleTopPicByTid(post.tid); toppic.replies += 1; toppic.lastauthor = iPow.function.StringHelper.GetAnonyIP(); toppic.lastauthorid = 0; int res = iPow.DataClass.jz.Querys.IrainDb.SaveChanges(); //更新新鲜事儿首页会显示这些信息的 iPow.DataSys.sns_feed_template tmeplate = iPow.DataClass.jz.Querys.GetSingleFeedTemplateByType("forum_reply"); iPow.DataSys.sns_feed feed = iPow.DataClass.jz.Querys.IrainDb.sns_feed.CreateObject(); //这个地方得改改,不过现在,还不晓得怎么改的 feed.appid = "0"; feed.feedtype = 0; feed.fid = 0; feed.type = "forum_reply"; feed.cTime = (int?)post.dateline; feed.uid = 0; feed.username = iPow.function.StringHelper.GetAnonyIP(); feed.title_data = feed.username + "回复了主题帖:<a href='/topic/" + post.tid + "/x' target='_blank'>" + toppic.subject + "</a>"; feed.body_data = feed.title_data; Webdiyer.WebControls.Mvc.PagedList <iPow.DataClass.jz.SinglePostDetail> model = null; model = iPow.DataClass.jz.Querys.GetTopPicPostDetailListById(post.tid, 1, pageSize, "last"); return(PartialView("ListTopicPartital", model)); #endregion } else { #region 添加新帖子 sns_topic toppic = new sns_topic(); sns_Post post = new sns_Post(); sns_PostContent postContent = new sns_PostContent(); postContent.isHtml = 0; if (picurl == null) { postContent.message = content; } else { postContent.message = content + "<br/>" + picurl; } postContent.picture = ""; if (username == null) { post.author = iPow.function.StringHelper.GetRealIP(); toppic.author = iPow.function.StringHelper.GetRealIP(); toppic.lastauthor = iPow.function.StringHelper.GetRealIP(); } else { post.author = username; toppic.author = username; toppic.lastauthor = username; } post.fid = Convert.ToInt32(fid); post.authorico = 0; post.authorid = 0; post.subject = title; post.dateline = iPow.function.DateHelper.GetNowToMysqlTime(); post.up = 0; post.wave = 0; post.postip = iPow.function.StringHelper.GetRealIP(); post.replyfloor = 0; toppic.dateline = iPow.function.DateHelper.GetNowToMysqlTime(); toppic.lasttime = iPow.function.DateHelper.GetNowToMysqlTime(); toppic.fid = Convert.ToInt32(fid); toppic.authorico = 0; toppic.authorid = 0; toppic.lastauthorid = 0; toppic.subject = title; iPow.DataClass.jz.Querys.IrainDb.sns_topic.AddObject(toppic); int res = iPow.DataClass.jz.Querys.IrainDb.SaveChanges(); if (res > 0) { sns_topic topic = iPow.DataClass.jz.Querys.GetSingleTopPicBySubject(title); int tid = topic.tid; post.tid = tid; postContent.tid = tid; iPow.DataClass.jz.Querys.IrainDb.sns_Post.AddObject(post); iPow.DataClass.jz.Querys.IrainDb.sns_PostContent.AddObject(postContent); iPow.DataClass.jz.Querys.IrainDb.SaveChanges(); } return(RedirectToAction("ListTopic", "Forum", new { tid = post.tid, num = "", pageIndex = 1 })); ////获得活动的名称 //string title1 = FroumModels.irainbow.sns_forum.Where(o => o.fid == post.fid).SingleOrDefault().name; //ViewBag.Name = title; //return PartialView("ForumListTopicC", new FroumModels(post.fid, title1, null, 60)); #endregion } } catch (Exception ex) { throw; } }