Example #1
0
        /// <summary>
        /// Froms the forumPost edit model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>New ForumPost from ForumPostEditModel</returns>
        public static ForumPost ForumPostEditModelToForumPost(ForumPostEditModel model)
        {
            var post = new ForumPost
            {
                ForumPostId = model.ForumPostId,
                ThreadId = model.ThreadId,
                Modified = DateTime.Now,
                Username = model.Username,
                Content = HtmlSanitizer.sanitize(model.Content)
            };

            return post;
        }
Example #2
0
        /// <summary>
        /// Toes the forum post edit model.
        /// </summary>
        /// <param name="post">The post.</param>
        /// <returns>Forum Post Edit Model</returns>
        public static ForumPostEditModel ForumPostToForumPostEditModel(ForumPost post)
        {
            var viewModel = new ForumPostEditModel
            {
                ForumPostId = post.ForumPostId,
                ThreadId = post.ThreadId,
                Username = post.Username,
                Content = post.Content
            };

            return viewModel;
        }
        public async Task<ActionResult> EditPost(ForumPostEditModel model)
        {
            if (ModelState.IsValid)
            {
                var forumPost = ForumMapping.ForumPostEditModelToForumPost(model);
                forumPost.Username = User.Identity.Name;
                if (model.New)
                {
                    db.ForumPosts.Add(forumPost);
                }
                else
                {
                    db.Entry(forumPost).State = EntityState.Modified;
                }

                await db.SaveChangesAsync();

                return RedirectToAction("ViewThread", new {threadId = model.ThreadId});
            }
            else
            {
                if (model.Content == null || model.Content.Length <= 0)
                {
                    ModelState.AddModelError("", "Please enter some content.");
                }
                else
                {
                    ModelState.AddModelError("", "There are errors in your post, please try reducing the ammount of text and try again.");
                }

                return View(model);
            }
        }