Esempio n. 1
0
 public void AddThread(Forum_Thread NewThread)
 {
     db.Forum_Threads.InsertOnSubmit(NewThread);
 }
Esempio n. 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;
 }
Esempio n. 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;
 }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 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);
 }
Esempio n. 6
0
		private void detach_Forum_Threads(Forum_Thread entity)
		{
			this.SendPropertyChanging();
			entity.Forum_User = null;
		}
Esempio n. 7
0
 partial void DeleteForum_Thread(Forum_Thread instance);
Esempio n. 8
0
 partial void UpdateForum_Thread(Forum_Thread instance);
Esempio n. 9
0
 partial void InsertForum_Thread(Forum_Thread instance);
Esempio n. 10
0
		private void attach_Forum_Threads(Forum_Thread entity)
		{
			this.SendPropertyChanging();
			entity.Forum_Category = this;
		}