public ActionResult Add(string title, int classify, string content) { List<Plate> platelist = new List<Plate>(); platelist = (from p in db.Plates where p.IsColse == false select p).ToList(); ViewBag.platelist = platelist; if (ModelState.IsValid) { try { User user = new User(); db.Users.Find(CurrentUser.ID); user.Integration += 20; IntegrationRecord integration = new IntegrationRecord(); integration.Hint = "发布帖子送积分"; integration.Integration = 20; integration.Time = DateTime.Now; integration.UserID = CurrentUser.ID; db.IntegrationRecords.Add(integration); db.SaveChanges(); Topic topic = new Topic(); topic.Title = title; topic.Content = content; topic.Top = false; topic.Time = DateTime.Now; topic.PlateID = classify; topic.UserID = CurrentUser.ID; topic.Report = 0; topic.Reward = 5; topic.Browses = 0; topic.IsOfficeIdentified = false; topic.IsShow = true; db.Topics.Add(topic); db.SaveChanges(); return Redirect("/Bbs/Index"); } catch (Exception ex) { ModelState.AddModelError("", "数据异常,请审核后重新提交"); log.Error(new LogContent("增加主题失败", Helpers.HttpHelper.GetIPAddress()), ex); } } else { ModelState.AddModelError("", "信息不全,请审核后提交"); } ViewBag.platelist = db.Plates.Where(x => x.IsColse == false).ToList(); return View(); }
public ActionResult Show(int id, int p = 0) { User user = new User(); Topic topic = new Topic(); topic = db.Topics.Find(id); if(topic!=null) { if (topic.IsShow) { try { topic.Browses = topic.Browses + 1; db.SaveChanges(); ViewBag.topic = topic; user = db.Users.Where(u => u.ID == topic.UserID).SingleOrDefault(); List<Topic> topics = new List<Topic>(); topics = db.Topics.Where(t => t.UserID == user.ID).ToList(); ViewBag.utopiccount = topics.Count(); var count = topic.Replies.Count(); ViewBag.topics = topics; ViewBag.user = user; ViewBag.count = count; List<vReply> replies = new List<vReply>(); IEnumerable<Reply> query = topic.Replies.OrderByDescending(t => t.Time).Where(t => t.FatherID == null).AsEnumerable(); ViewBag.PageInfo = PagerHelper.Do(ref query, 5, p); foreach (var item in query) { replies.Add(new vReply(item)); } if (CurrentUser == null) { ViewBag.IsCollected = false; } else { var collect = db.Collects.Where(c => c.CollectTypeAsInt == 2 && c.TID == topic.PlateID && c.UserID == CurrentUser.ID).FirstOrDefault(); if (collect == null) { ViewBag.IsCollected = false; } else { ViewBag.IsCollected = true; } } ViewBag.Plate = db.Plates.Find(topic.PlateID); ViewBag.Collections = db.Collects.Where(c => c.CollectTypeAsInt == 2 && c.TID == topic.PlateID).Count(); return View(replies); } catch (Exception ex) { log.Error(new LogContent("显示主题出错", Helpers.HttpHelper.GetIPAddress()), ex); return Redirect("/Shared/Info?msg=主题不存在,请不要不合理操作"); } } else { return Redirect("/Shared/Info?msg=主题已关闭,请不要不合理操作"); } } else { return Redirect("/Shared/Info?msg=主题不存在,请不要不合理操作"); } }