Exemple #1
0
 public ActionResult Create(TagIndexViewModel vm, int id)
 {
     vm.Post       = _postRepo.GetPublishedPostById(id);
     vm.TagsOnPost = _tagRepository.GetTagsByPostId(id);
     try
     {
         foreach (Tag t in vm.TagsOnPost)
         {
             var postTag = _postTagRepo.GetPostTagByPostandTag(t.Id, id);
             if (postTag != null)
             {
                 _postTagRepo.DeletePostTag(postTag.Id);
             }
         }
         foreach (int tagId in vm.AreChecked)
         {
             var newPostTag = new PostTag()
             {
                 PostId = id,
                 TagId  = tagId
             };
             _postTagRepo.AddPostTag(newPostTag);
         }
         return(RedirectToAction("Details", "Post", new { id = id }));
     }
     catch
     {
         return(View());
     }
 }