public ActionResult Add(PostTagsAddViewModel viewModel) { ValidatePostTags(viewModel); if (ModelState.IsValid) { var postTags = new PostTags() { PostId = viewModel.PostId, TagId = viewModel.TagId, }; _postTagsRepository.Add(postTags); TempData["Message"] = "Your tag was successfully added!"; return(RedirectToAction("Edit", "Post", new { id = viewModel.PostId })); } viewModel.Post = _postRepository.Get(viewModel.PostId); viewModel.Init(_tagRepository); return(View(viewModel)); }
// GET: PostTags/Create public ActionResult Add(int postId) { var post = _postRepository.Get(postId); if (post == null) { return(HttpNotFound()); } var viewModel = new PostTagsAddViewModel() { Post = post }; viewModel.Init(_tagRepository); return(View(viewModel)); }