public void SetBookReview(ReviewInputModel inputFromUser, string user) { var reviewForBook = _reviewRepo.GetReviewByBookId(inputFromUser.bookId); double sumOfAllReview = inputFromUser.Ratings; for (int i = 0; i < reviewForBook.Count; i++) { sumOfAllReview += reviewForBook[i].Ratings; } double newRating = sumOfAllReview / (reviewForBook.Count + 1); ReviewTwo newReview = new ReviewTwo { reviewBookId = inputFromUser.bookId, Ratings = inputFromUser.Ratings, Description = inputFromUser.Description, reviewFromUserName = _bookRepo.getUserName(user) }; _reviewRepo.SetReview(newReview); var updatedBook = _bookRepo.getBookEntityModel(inputFromUser.bookId); updatedBook.rating = newRating; _bookRepo.UpdateABook(updatedBook, inputFromUser.bookId); }