示例#1
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));
            }
        }
示例#2
0
        public IActionResult UpdatePostTags(List <int> tagIds, int postId)
        {
            _postTagRepository.DeletePostTag(postId);

            foreach (int tagId in tagIds)
            {
                _postTagRepository.AddPostTag(tagId, postId);
            }

            return(NoContent());
        }
示例#3
0
        public ActionResult Create(PostTagViewModel vm, int id)
        {
            vm.Post        = _postRepository.GetPublishedPostById(id);
            vm.PostTagList = _tagRepository.GetTagsByPostId(id);
            vm.AllTags     = _tagRepository.GetAllTags();
            try
            {
                foreach (Tags t in vm.PostTagList)
                {
                    var postTag = _postTagRepository.GetPostTagbyPostWithTag(t.Id, id);
                    if (postTag != null)
                    {
                        _postTagRepository.DeletePostTag(postTag.Id);
                    }
                }


                if (vm.IsSelected != null)
                {
                    foreach (int tagId in vm.IsSelected)

                    {
                        var aPostTag = new PostTag()
                        {
                            PostId = id,
                            TagId  = tagId
                        };
                        _postTagRepository.AddTagToPost(aPostTag);
                    }
                    return(RedirectToAction("UserPostDetails", "Post", new { id = id }));
                }
                else
                {
                    return(RedirectToAction("UserPostDetails", "Post", new { id = id }));
                }
            }
            catch
            {
                return(View(vm));
            }
        }
示例#4
0
 public IActionResult Delete(int id)
 {
     _postTagRepository.DeletePostTag(id);
     return(NoContent());
 }