Example #1
0
        public void CalculateAverageRating(BookSellerContext context)
        {
            var book = context.Book.Find(this.BookId);

            book.AverageRating = Math.Round(Convert.ToDecimal(context.Review.Where(item => item.BookId == this.BookId).Average(item => item.Rating)), 1);
            context.SaveChanges();
        }
Example #2
0
        public override bool Validate(out string error, BookSellerContext context)
        {
            if (Author is Author author)
            {
                this.AuthorId = author.Id;
                this.Author   = null;
            }

            if (!context.Author.Exists(this.AuthorId))
            {
                error = $"{nameof(AuthorId)} - `{this.AuthorId}` does not exist in the database.";
                return(false);
            }
            return(base.Validate(out error, context));
        }
Example #3
0
 public override void IncludeChildren(BookSellerContext context)
 => context.Book.Include(book => book.Author).FirstOrDefaultAsync(book => book.Id == this.Id);
Example #4
0
 public override void IncludeChildren(BookSellerContext context)
 {
     context.Review.Include(review => review.Book).FirstOrDefaultAsync(review => review.Id == this.Id);
     context.Book.Include(book => book.Author).FirstOrDefaultAsync(book => book.Id == this.BookId);
 }
 public virtual void IncludeChildren(BookSellerContext context)
 {
 }
 public virtual bool Validate(out string error, BookSellerContext context)
 {
     error = null;
     return(true);
 }