Beispiel #1
0
        private BlogPost CreatePost(int index, Blog blog, IList <User> users, Random random)
        {
            var month = 12 - (index * 2) / 28;
            var day   = 28 - (index * 2) % 28;
            var title = blog.Name + " Post " + index;
            var user  = users[random.Next(users.Count)];

            var hour   = random.Next(23);
            var minute = random.Next(59);
            var second = random.Next(59);

            var post = new BlogPost
            {
                Title       = title,
                PublishDate = new DateTime(2011, month, day, hour, minute, second),
                Author      = user,
                Blog        = blog
            };

            for (int i = 0; i < random.Next(10); i++)
            {
                var comment = new Comment
                {
                    Content     = "Comment " + i,
                    PublishDate = new DateTime(2011, month, day, random.Next(23), random.Next(59), random.Next(59))
                };

                post.AddComment(comment);
            }

            post.Content = post.Title + " content";

            return(post);
        }
Beispiel #2
0
        public JsonResult CommentSubmit(BlogCommentViewModel commentViewModel)
        {
            BlogPost blogPost = new BlogPost(commentViewModel.PostID);

            TKS.Models.User user = new TKS.Models.User();
            commentViewModel.Author      = user.UserName;
            commentViewModel.CommentDate = DateTime.Now;
            commentViewModel.Email       = user.Email;
            commentViewModel.IP          = Request.UserHostAddress;
            blogPost.AddComment(commentViewModel);

            return(Json(true));
        }