public void AddTagsToBlog(int blogID, List <Tag> tagIDs) { foreach (var tag in tagIDs) { _blogTagRepo.AddTagToBlog(blogID, tag.TagId); } }
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))); }