public IActionResult EditBlogPost(EditBlogPostViewModel model) { if (ModelState.IsValid) { var blogPost = _blogPostRepository.GetByTitle(model.OldTitle); blogPost.Title = model.Title; blogPost.Body = model.Body; blogPost.DatePublished = model.DatePublished; blogPost.IsPublished = model.IsPublished; _blogPostRepository.ClearContentTags(blogPost.Id); foreach (var tagName in model.AvailableContentTags) { var contentTag = _contentTagRepository.GetByName(tagName); var blogtag = new BlogPostContentTag { BlogPost = blogPost, ContentTag = contentTag, BlogPostId = blogPost.Id, ContentTagId = contentTag.Id }; blogPost.BlogPostsContentTags.Add(blogtag); } _blogPostRepository.Update(blogPost); } return(RedirectToAction("blogposts")); }