Beispiel #1
0
 public ActionResult PostComment(int postId, string name, string content)
 {
     var db = new BlogDb(@"Data Source=.\sqlexpress;Initial Catalog=Blog;Integrated Security=True");
     Comment comment = new Comment {PostId = postId, Content = content, Name = name, Date = DateTime.Now};
     db.AddComment(comment);
     return RedirectToAction("Post", new {pid = postId});
 }
Beispiel #2
0
 public ActionResult Post(int pid)
 {
     var db = new BlogDb(@"Data Source=.\sqlexpress;Initial Catalog=Blog;Integrated Security=True");
     var post = db.GetPostById(pid);
     var comments = db.GetCommentsForPost(pid);
     var vm = new BlogPostViewModel { Post = post, Comments = comments };
     return View(vm);
 }
Beispiel #3
0
 public ActionResult Post(int postId)
 {
     var db = new BlogDb(_connectionString);
     var vm = new BlogSingleViewModel();
     vm.Post = db.GetPostById(postId);
     vm.Comments = db.GetCommentsForPost(postId);
     vm.Tags = db.GetTagsForPost(postId);
     return View(vm);
 }
Beispiel #4
0
 public ActionResult Index()
 {
     var db = new BlogDb(@"Data Source=.\sqlexpress;Initial Catalog=Blog;Integrated Security=True");
     var posts = db.GetTop5Posts();
     foreach (Post p in posts)
     {
         p.Content = StripHtml(p.Content).Substring(0, 200) + "....";
     }
     var vm = new HomePageViewModel { Posts = posts };
     return View(vm);
 }
Beispiel #5
0
 public ActionResult Index()
 {
     var db = new BlogDb(_connectionString);
     var viewModel = new BlogsIndexViewModel
     {
         Posts = db.GetLastFive()
     };
     foreach (Post p in viewModel.Posts)
     {
         p.Text = StripTagsRegex(p.Text).Substring(0, 300) + "...";
     }
     return View(viewModel);
 }
Beispiel #6
0
        public ActionResult Comment(string name, string text, int postId)
        {
            var db = new BlogDb(_connectionString);
            Comment comment = new Comment
            {
                Date = DateTime.Now,
                Name = name,
                Text = text,
                PostId = postId
            };

            db.AddComment(comment);
            return RedirectToAction("Post", new {postId = postId});
        }
Beispiel #7
0
        public ActionResult AddPost(string content, string title, string tags)
        {
            var db = new BlogDb(@"Data Source=.\sqlexpress;Initial Catalog=Blog;Integrated Security=True");
            Post post = new Post
            {
                Content = content,
                Title = title,
                Date = DateTime.Now
            };
            db.AddPost(post);
            db.AddTagsToPost(tags, post.Id);

            return RedirectToAction("Index");
        }
Beispiel #8
0
        public ActionResult AddPost(string title, string text, string tags)
        {
            var db = new BlogDb(_connectionString);
            var post = new Post { Date = DateTime.Now, Text = text, Title = title };
            db.AddPost(post);
            IEnumerable<Tag> postTags = tags.Split(',').Select(t =>
            {
                int tagId = db.AddTag(t);
                return new Tag
                {
                    Id = tagId,
                    Name = t
                };
            });

            db.AddTagsToPost(post, postTags);
            return RedirectToAction("Index", "Blog");
        }