Esempio n. 1
0
        public ActionResult Edit(BlogPostVM editedBlogPost)
        {
            if (ModelState.IsValid)
            {
                _blogPostRepo.EditBlogPost(editedBlogPost.BlogPost);
                var blogPostID = editedBlogPost.BlogPost.BlogPostId;
                _blogCategoryRepo.DeleteCategoryFromBlogPost(blogPostID);

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

                string[] postTags = editedBlogPost.Tag.TagName.ToLower().Split(' ');
                editedBlogPost.Tags = _tagRepo.SelectAllTags(postTags);
                _blogTagRepo.DeleteTagFromBlog(blogPostID);
                foreach (var tag in editedBlogPost.Tags)
                {
                    _blogTagRepo.AddTagToBlog(blogPostID, tag.TagId);
                }

                return(RedirectToAction("Index", "Home"));
            }
            return(View(editedBlogPost));
        }
Esempio n. 2
0
        public void ProcessEditedBlogPost(BlogPost editedBlogPost)
        {
            editedBlogPost.EditDate = DateTime.Now;
            _blogPostRepo.EditBlogPost(editedBlogPost);
            int blogPostID = editedBlogPost.BlogPostId;

            // remove all existing Categories from blog post
            _blogCategoryRepo.DeleteCategoryFromBlogPost(blogPostID);

            // add selected categories to this blog post
            foreach (var category in editedBlogPost.AssignedCategories)
            {
                _blogCategoryRepo.AddCategoryToBlog(blogPostID, category.CategoryId);
            }

            List <string> justTagNames = new List <string>();

            foreach (var tag in editedBlogPost.AssignedTags)
            {
                justTagNames.Add(tag.TagName);
            }
            // add newly created tag names to tag repo, assigns them valid tagIDs, returns list of valid Tag objects
            editedBlogPost.AssignedTags = _tagRepo.AddAllTags(justTagNames);
            // remove all assigned tags to this blogPost
            _blogTagRepo.DeleteTagFromBlog(blogPostID);
            // assign newly created Tags to this blog post
            foreach (var tag in editedBlogPost.AssignedTags)
            {
                _blogTagRepo.AddTagToBlog(blogPostID, tag.TagId);
            }
        }