예제 #1
0
        // GET: PostTagController/Create
        public ActionResult Create(int id)
        {
            IEnumerable <Tag> tags = _tagRepository.GetAllTags();

            List <int> tagsSelected = new List <int>();
            Post       post         = _postRepository.GetPublishedPostById(id);


            //creating an instance of the view model class
            PostTagFormViewModel vm = new PostTagFormViewModel()
            {
                PostTag      = new PostTag(),
                Tag          = tags,
                TagsSelected = tagsSelected,
                PostId       = id
            };

            if (post.UserProfileId == int.Parse(User.Claims.ElementAt(0).Value))
            {
                return(View(vm));
            }
            else
            {
                return(NotFound());
            }
        }
예제 #2
0
        public ActionResult Create(PostTagFormViewModel postTagVM)

        {
            try
            {
                foreach (int TagId in postTagVM.TagsSelected)
                {
                    PostTag newPostTag = new PostTag
                    {
                        PostId = postTagVM.PostId,
                        TagId  = TagId
                    };
                    _postTagRepository.AddPostTag(newPostTag);
                }
                return(RedirectToAction("Details", "Post", new { id = postTagVM.PostId }));
            }
            catch {
                IEnumerable <Tag> tags = _tagRepository.GetAllTags();

                List <int> tagsSelected = new List <int>();

                PostTagFormViewModel vm = new PostTagFormViewModel()
                {
                    PostTag      = new PostTag(),
                    Tag          = tags,
                    TagsSelected = tagsSelected,
                    PostId       = postTagVM.PostId
                };
                return(View(vm));
            }
        }
예제 #3
0
        public ActionResult Delete(PostTagFormViewModel postTagVM)
        {
            try
            {
                foreach (int PostTagId in postTagVM.PostTagsSelected)
                {
                    _postTagRepository.DeletePostTag(PostTagId);
                }
                return(RedirectToAction("Details", "Post", new { id = postTagVM.PostId }));
            }
            catch
            {
                IEnumerable <PostTag> postTags = _postTagRepository.GetAllPostTagsByPostId(postTagVM.PostId);

                List <int> postTagsSelected = new List <int>();

                //creating an instance of the view model class
                PostTagFormViewModel vm = new PostTagFormViewModel()
                {
                    PostTag          = new PostTag(),
                    PostTagsSelected = postTagsSelected,
                    PostId           = postTagVM.PostId,
                    PostTags         = postTags
                };
                return(View(vm));
            }
        }