public ActionResult Create(PostViewModel viewModel) { if (ModelState.IsValid) { repository.AddNewPost(viewModel.Post); string action = "../Post/Index/" + viewModel.Post.BlogID.ToString(); return RedirectToAction(action); } return View(viewModel); }
public ActionResult Create(int id) { Blog blog = repository.GetBlogByID(id); List<Post> posts = repository.GetPostsByBlogID(id); Blogger blogger = repository.GetBloggerByID(blog.BloggerID); Post newPost = new Post(); newPost.BlogID = blog.BlogID; newPost.DateCreated = DateTime.Now; PostViewModel viewModel = new PostViewModel(blog, blogger, newPost, posts); return View(viewModel); }
public ActionResult Index(int id) { List<Post> posts = repository.GetPostsByBlogID(id); Blog blog = repository.GetBlogByID(id); Blogger blogger = repository.GetBloggerByID(blog.BloggerID); PostViewModel viewModel = new PostViewModel(blog, blogger, null, posts); return View(viewModel); }