Esempio n. 1
0
        //----------------------------------------------

        public static IStatusGeneric <BookWithEvents> CreateBook(string title, string description, DateTime publishedOn,
                                                                 string publisher, decimal price, string imageUrl, ICollection <AuthorWithEvents> authors)
        {
            var status = new StatusGenericHandler <BookWithEvents>();

            if (string.IsNullOrWhiteSpace(title))
            {
                status.AddError("The bookWithEvents title cannot be empty.");
            }

            var book = new BookWithEvents
            {
                BookId      = Guid.NewGuid(),
                Title       = title,
                Description = description,
                PublishedOn = publishedOn,
                Publisher   = publisher,
                ActualPrice = price,
                OrgPrice    = price,
                ImageUrl    = imageUrl,
                //We need to initialise the AuthorsOrdered string when the entry is created
                AuthorsOrdered = string.Join(", ", authors.Select(x => x.Name)),
                //We don't need to initialise the ReviewsCount and the ReviewsAverageVotes  as they default to zero
                _reviews = new HashSet <ReviewWithEvents>()       //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 <BookAuthorWithEvents>(authors.Select(a => new BookAuthorWithEvents(book, a, order++)));
            if (!book._authorsLink.Any())
            {
                status.AddError("You must have at least one Author for a bookWithEvents.");
            }

            return(status.SetResult(book));
        }
 internal BookAuthorWithEvents(BookWithEvents bookWithEvents, AuthorWithEvents authorWithEvents, byte order)
 {
     Book   = bookWithEvents;
     Author = authorWithEvents;
     Order  = order;
 }