Ejemplo n.º 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();
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 3
0
 public override void IncludeChildren(BookSellerContext context)
 => context.Book.Include(book => book.Author).FirstOrDefaultAsync(book => book.Id == this.Id);
Ejemplo n.º 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);
 }
Ejemplo n.º 5
0
 public virtual void IncludeChildren(BookSellerContext context)
 {
 }
Ejemplo n.º 6
0
 public virtual bool Validate(out string error, BookSellerContext context)
 {
     error = null;
     return(true);
 }