public ActionResult Create(int forumId, FormCollection form)
        {
           
            Forum forumToUpdate = db.Forums.Single(
                f => f.ForumId == forumId);

            Post newPost = new Post
            {                
                Poster = User.Identity.Name,                
                PostDate = DateTime.Now
            };

            Thread newThread = new Thread 
            {
                ThreadStarter = User.Identity.Name,
                Posts = new List<Post>{ newPost }
            };

            newPost.ContainingThread = newThread;
            newThread.ContainingForum = forumToUpdate;
            forumToUpdate.Threads.Add(newThread);            

            try
            {
                UpdateModel(newPost, "ThePost");
                UpdateModel(newThread, "TheThread");
                db.SaveChanges();
                return RedirectToAction("Index", new { id = forumToUpdate.ForumId });
            }
            catch
            {
                return View(new CreateThreadViewModel { TheForum = forumToUpdate });
            }
        }
 public bool OwnsPost(Post thePost)
 {
     return HttpContext.Current.User.Identity.Name.Equals(thePost.Poster);
 }
 /// <summary>
 /// Returns the id attribute value for the given
 /// post as a string.
 /// </summary>
 /// <param name="aPost">The post to get the DOM id attribute of</param>
 /// <returns>The DOM element id attribute value.</returns>
 public static string GetDomPostId(Post aPost)
 {
     return DOM_POST_PREFIX_ID + aPost.PostId;
 }
        public ActionResult CreatePost(int threadId, FormCollection form)
        {
            Thread theThread = db.Threads.Single(t => t.ThreadId == threadId);

            Post thePost = new Post();
            thePost.ContainingThread = theThread;
            thePost.Poster = User.Identity.Name;            
            thePost.PostDate = DateTime.Now;

            /*Post thePost = new Post
            {
                PostContent = postContent,
                Poster = User.Identity.Name,
                NegativeRatings = 0,
                PositiveRatings = 0,
                SpamFlags = 0,
                PostDate = DateTime.Now
            };*/

            ThreadViewModel tvm = new ThreadViewModel 
            { 
                Thread = theThread
            };
            try
            {
                this.UpdateModel<Post>(thePost, "Post");
                theThread.Posts.Add(thePost);
                db.SaveChanges();

                int lastPageSize = theThread.Posts.Count % Preferences.PAGE_SIZE;
                int lastPage = theThread.Posts.Count / Preferences.PAGE_SIZE;

                lastPage = (lastPageSize == 0) ? lastPage : lastPage + 1;

                tvm.PageSize = Preferences.PAGE_SIZE;
                tvm.PageNumber = lastPage;

                return PartialView("Posts", tvm);
            }
            catch
            {
                tvm.PageSize = Preferences.PAGE_SIZE;
                tvm.PageNumber = this.pageNumber;
                return PartialView("Posts", tvm);
            }
        }