Beispiel #1
0
        // 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));
        }