public static IStatusGeneric <DddBook> CreateBook(string title, string description, DateTime publishedOn, string publisher, decimal price, string imageUrl, ICollection <DddAuthor> authors) { var status = new StatusGenericHandler <DddBook>(); if (string.IsNullOrWhiteSpace(title)) { status.AddError("The book title cannot be empty."); } var book = new DddBook { Title = title, Description = description, PublishedOn = publishedOn, Publisher = publisher, ActualPrice = price, OrgPrice = price, ImageUrl = imageUrl, _reviews = new HashSet <DddReview>() //We add an empty list on create. I allows reviews to be added when building test data }; if (authors == null) { throw new ArgumentNullException(nameof(authors)); } byte order = 0; book._authorsLink = new HashSet <DddBookAuthor>(authors.Select(a => new DddBookAuthor(book, a, order++))); if (!book._authorsLink.Any()) { status.AddError("You must have at least one Author for a book."); } return(status.SetResult(book)); }
internal DddBookAuthor(DddBook dddBook, DddAuthor dddAuthor, byte order) { DddBook = dddBook; DddAuthor = dddAuthor; Order = order; }