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(); }
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)); }
public override void IncludeChildren(BookSellerContext context) => context.Book.Include(book => book.Author).FirstOrDefaultAsync(book => book.Id == this.Id);
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); }