// GET: PostTagsController public ActionResult Index() { int postId = Int32.Parse(HttpContext.Request.Query["postId"]); Post post = _postRepo.GetPublishedPostById(postId); if (post == null) { return(NotFound()); } List <PostTag> postTags = _postTagRepo.GetPostTagsbyPostId(postId);; List <Tag> tags = _tagRepo.GetTags(); foreach (PostTag pTag in postTags) { int tagId = pTag.TagId; tags.RemoveAll(t => t.Id == tagId); } PostTagIndexViewModel vm = new PostTagIndexViewModel { Post = post, PostTags = postTags, Tags = tags }; return(View(vm)); }
// GET: PostTagsController public ActionResult Index() { //gey postId fro query string int postId = Int32.Parse(HttpContext.Request.Query["postId"]); Post post = _postRepo.GetPostById(postId); if (post == null) { return(NotFound()); } List <PostTag> postTags = _postTagRepo.GetPostTagsbyPostId(postId);; //holds tags that are not assigned to post List <Tag> tags = _tagRepo.GetAllTags(); //add tagids the are attached to post foreach (PostTag pTag in postTags) { int tagId = pTag.TagId; //remove the tag if the Id is found tags.RemoveAll(t => t.Id == tagId); } PostTagIndexViewModel vm = new PostTagIndexViewModel { Post = post, PostTags = postTags, //post-tag relationships for this post Tags = tags //unsued tags }; return(View(vm)); }
public IActionResult Details(int id) { var post = _postRepository.GetPublishedPostById(id); List <PostTag> postTags = _postTagRepository.GetPostTagsbyPostId(id); if (post == null) { int userId = GetCurrentUserProfileId(); post = _postRepository.GetUserPostById(id, userId); if (post == null) { return(NotFound()); } } PostDetailViewModel vm = new PostDetailViewModel { Post = post, PostTags = postTags }; return(View(vm)); }