public void AddCategory(String categoryName, String categoryDescription, String parentCategory)
        {
            String slug = categoryName.Slugify();
            if (!String.IsNullOrEmpty(parentCategory))
            {
                //Verify parent category exists.
                if (!categories.Any(c => c.Name.Equals(parentCategory, StringComparison.OrdinalIgnoreCase)))
                {
                    throw new ArgumentException("There is not category named " + parentCategory + " to be used as parent", "parentCategory");
                }
            }
            //Verify no category with the same name in the system
            if (categories.Any(c => c.Name.Equals(categoryName, StringComparison.OrdinalIgnoreCase)))
            {
                throw new ArgumentException("There is already a category named " + categoryName, "categoryName");
            }

            Category parent = null;
            if (!String.IsNullOrEmpty(parentCategory))
            {
                parent = categories
                    .Where(c => c.Name.Equals(parentCategory, StringComparison.OrdinalIgnoreCase))
                    .Single();
            }
            String path = parent == null ? categoryName : parent.Path + "/" + categoryName;
            String parentName = parent == null ? String.Empty : parent.Name;
            CategoryAdded evt = new CategoryAdded(categoryName,  parentName, slug, categoryDescription, path);

            RaiseEvent(evt);
        }
Beispiel #2
0
 /// <summary>
 /// Factory method to create a post
 /// </summary>
 /// <param name="factory">The factory to be used for AggregateRootCreation</param>
 /// <param name="title"></param>
 /// <param name="textContent"></param>
 /// <returns></returns>
 public static Post CreatePost(
     AggregateRootFactory factory,
     String title,
     String textContent,
     String excerpt,
     String blogName)
 {
     //Slug is created replacing any non number or letter char with a dash
     //accents are removed
     String slug = title.Slugify();
     if (String.IsNullOrEmpty(excerpt))
     {
         //Need to calculate the excerpt of the post, in this version just take some text from the
         //body of the post.
         HtmlDocument doc = new HtmlDocument();
         doc.LoadHtml(textContent);
         excerpt = doc.DocumentNode.InnerText;
         if (excerpt.Length > 200) excerpt = excerpt.Substring(0, 200) + "...";
     }
     var evt = new PostCreated(title, textContent, slug, blogName, excerpt);
     return factory.Create<Post>(evt);
 }