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}); }
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); }
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); }
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); }
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); }
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}); }
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"); }
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"); }