BetterCms.Module.Blog.Services.DefaultBlogMLService.ImportBlogs C# (CSharp) Method

ImportBlogs() public method

public ImportBlogs ( BlogMLBlog blogPosts, List modifications, IPrincipal principal, bool createRedirects = false, bool RecreateCategoryTree = true, bool ReuseExistingCategories = false ) : List
blogPosts BlogMLBlog
modifications List
principal IPrincipal
createRedirects bool
RecreateCategoryTree bool
ReuseExistingCategories bool
return List
        public List<BlogPostImportResult> ImportBlogs(BlogMLBlog blogPosts, List<BlogPostImportResult> modifications,
            IPrincipal principal, bool createRedirects = false, bool RecreateCategoryTree = true, bool ReuseExistingCategories = false)
        {
            List<BlogPostImportResult> createdBlogPosts = null;
            if (blogPosts != null)
            {
                var blogs = new List<BlogMLPost>();
                foreach (var blogML in blogPosts.Posts)
                {
                    var requestBlogPost = modifications.FirstOrDefault(rb => rb.Id == blogML.ID);
                    if (requestBlogPost != null)
                    {
                        blogs.Add(blogML);
                    }
                }

                // Import authors and categories
                unitOfWork.BeginTransaction();

                var newTreeList = new List<CategoryTree>();
                var newCategoriesList = new List<Category>();

                var createdAuthors = new List<Author>();
                var authors = ImportAuthors(blogPosts.Authors, createdAuthors, blogs);
                var categories = ImportCategories(blogPosts.Categories, blogs, ref newTreeList, ref newCategoriesList, ReuseExistingCategories, RecreateCategoryTree);

                unitOfWork.Commit();

                // Notify authors, categories created
                createdAuthors.ForEach(a => Events.BlogEvents.Instance.OnAuthorCreated(a));
                newTreeList.ForEach(Events.RootEvents.Instance.OnCategoryTreeCreated);
                newCategoriesList.ForEach(Events.RootEvents.Instance.OnCategoryCreated);

                // Import blog posts
                createdBlogPosts = ImportBlogPosts(principal, authors, categories, blogs, modifications, createRedirects);
            }

            return createdBlogPosts ?? new List<BlogPostImportResult>();
        }