コード例 #1
0
 public void AddThread(Forum_Thread NewThread)
 {
     db.Forum_Threads.InsertOnSubmit(NewThread);
 }
コード例 #2
0
 public int GetLastPost(Forum_Thread Thread, Forum_User User)
 {
     var Last = db.Forum_ViewedPosts.SingleOrDefault(P => P.Forum_User == User && P.Forum_Thread == Thread);
     return Last == null ? 0 : Last.LastPost;
 }
コード例 #3
0
 public void SetLastPost(Forum_Thread Thread, Forum_User User, int PostNumber, bool IncreaseOnly = true)
 {
     var Last = db.Forum_ViewedPosts.SingleOrDefault(P => P.Forum_User == User && P.Forum_Thread == Thread);
     if (Last == null)
     {
         Last = new Forum_ViewedPost();
         Last.Forum_Thread = Thread;
         Last.Forum_User = User;
         db.Forum_ViewedPosts.InsertOnSubmit(Last);
     }
     else if (Last.LastPost >= PostNumber && IncreaseOnly) return;
     Last.LastPost = PostNumber;
 }
コード例 #4
0
ファイル: ForumController.cs プロジェクト: Netriak/MvcForum
        public ActionResult NewThread(WritePostViewModel model, string button)
        {
            using (ForumRespository db = new ForumRespository())
            {
                Forum_Category Category = db.GetCategoryByID(model.id);
                if (Category == null) return NotFoundView("Category");

                model.AddNavigation(Category);
                model.AddNavigation("New thread");

                Forum_User Poster = GetCurrentUser(db);

                if (!db.CheckCategoryPermissions(Category, Poster, P => P.AllowNewThread))
                    return AuthenticationHelper.AccessDeniedView(model);

                if (String.Equals(button, "preview", StringComparison.InvariantCultureIgnoreCase))
                {
                    model.ShowPost = true;
                    model.PostHtml = PostParser.Parse(model.PostText);
                    ModelState.Clear();
                }
                else
                if (IsHttpPost)
                {
                    if (!AntiForgeryTokenValid)
                    {
                        ModelState.AddModelError("AntiForgery", "The antiforgery token was invalid.");
                    }
                    if (String.IsNullOrEmpty(model.ThreadTitle))
                    {
                        ModelState.AddModelError("ThreadTitle", "A thread title is required.");
                    }
                    if (ModelState.IsValid)
                    {
                        Forum_Thread NewThread = new Forum_Thread();
                        NewThread.Title = model.ThreadTitle;

                        NewThread.PosterID = Poster.UserID;

                        Forum_Post InitialPost = new Forum_Post();
                        InitialPost.TimeStamp = DateTime.Now;
                        InitialPost.PosterID = NewThread.PosterID;
                        InitialPost.PostText = model.PostText;
                        NewThread.Forum_Posts.Add(InitialPost);
                        NewThread.Posts = 1;
                        NewThread.LastPostTime = InitialPost.TimeStamp;
                        NewThread.CategoryID = model.id;
                        // Save and add thread to database
                        db.AddThread(NewThread);
                        db.SetLastPost(NewThread, Poster, 1);
                        db.Save();
                        return RedirectToAction("ViewCategory", new { id = model.id });
                    }
                }
                else
                {
                    ModelState.Clear();
                }
                model.EditTitle = true;
                model.Title = "Post new Thread";
                return View("WritePost", model);
            }
        }
コード例 #5
0
 public void DeleteThread(Forum_Thread ToDelete)
 {
     db.Forum_ViewedPosts.DeleteAllOnSubmit(from V in db.Forum_ViewedPosts where V.ThreadID == ToDelete.ThreadID select V);
     db.Forum_Posts.DeleteAllOnSubmit(ToDelete.Forum_Posts);
     db.Forum_Threads.DeleteOnSubmit(ToDelete);
 }
コード例 #6
0
ファイル: Forum.designer.cs プロジェクト: Netriak/MvcForum
		private void detach_Forum_Threads(Forum_Thread entity)
		{
			this.SendPropertyChanging();
			entity.Forum_User = null;
		}
コード例 #7
0
ファイル: Forum.designer.cs プロジェクト: Netriak/MvcForum
 partial void DeleteForum_Thread(Forum_Thread instance);
コード例 #8
0
ファイル: Forum.designer.cs プロジェクト: Netriak/MvcForum
 partial void UpdateForum_Thread(Forum_Thread instance);
コード例 #9
0
ファイル: Forum.designer.cs プロジェクト: Netriak/MvcForum
 partial void InsertForum_Thread(Forum_Thread instance);
コード例 #10
0
ファイル: Forum.designer.cs プロジェクト: Netriak/MvcForum
		private void attach_Forum_Threads(Forum_Thread entity)
		{
			this.SendPropertyChanging();
			entity.Forum_Category = this;
		}