示例#1
0
 public void AddTagsToBlog(int blogID, List <Tag> tagIDs)
 {
     foreach (var tag in tagIDs)
     {
         _blogTagRepo.AddTagToBlog(blogID, tag.TagId);
     }
 }
示例#2
0
        public ActionResult Post(BlogPostVM newBlogPost)
        {
            if (ModelState.IsValid)
            {
                var blogId = _blogPostRepo.AddBlogPost(newBlogPost.BlogPost);

                foreach (var category in newBlogPost.CategoryArray)
                {
                    _blogCategoryRepo.AddCategoryToBlog(blogId, int.Parse(category));
                }

                string[] postTags = newBlogPost.Tag.TagName.ToLower().Split(' ');
                newBlogPost.Tags = _tagRepo.SelectAllTags(postTags);

                foreach (var tag in newBlogPost.Tags)
                {
                    _blogTagRepo.AddTagToBlog(blogId, tag.TagId);
                }

                return(RedirectToAction("Index", "Home"));
            }
            return(View(PopulatedCategorySelectListItem(newBlogPost)));
        }