Example #1
0
        public ActionResult Create(Post model)
        {
            if ((from f in DbContext.Forums where f.ID == model.ForumID && f.FatherID != null select f).Count() == 0)
            {
                return(RedirectToAction("Message", "Shared", new { msg = "没有找到这个论坛版块!" }));
            }
            if (string.IsNullOrEmpty(model.Content))
            {
                return(RedirectToAction("Message", "Shared", new { msg = "内容不能为空!" }));
            }
            var topic = new CodeComb.Entity.Topic
            {
                ForumID   = model.ForumID,
                Title     = model.Title,
                Content   = model.Content,
                UserID    = ViewBag.CurrentUser.ID,
                Time      = DateTime.Now,
                Top       = false,
                LastReply = DateTime.Now
            };

            DbContext.Topics.Add(topic);
            DbContext.SaveChanges();
            return(RedirectToAction("Index", "Topic", new { id = topic.ID }));
        }
Example #2
0
 public ActionResult Create(Post model)
 {
     if ((from f in DbContext.Forums where f.ID == model.ForumID && f.FatherID != null select f).Count() == 0)
         return RedirectToAction("Message", "Shared", new { msg = "没有找到这个论坛版块!" });
     if(string.IsNullOrEmpty(model.Content))
         return RedirectToAction("Message", "Shared", new { msg = "内容不能为空!" });
     var topic = new CodeComb.Entity.Topic
     {
         ForumID = model.ForumID,
         Title = model.Title,
         Content = model.Content,
         UserID = ViewBag.CurrentUser.ID,
         Time = DateTime.Now,
         Top = false,
         LastReply = DateTime.Now
     };
     DbContext.Topics.Add(topic);
     DbContext.SaveChanges();
     return RedirectToAction("Index", "Topic", new { id = topic.ID });
 }