Esempio n. 1
0
        public void AddRating(int id, int rating)
        {
            //Byrja á að kalla á repo gera add to totalCount og totalRating, senda nidur bookId og rating
            _bookRepo.AddTotalRating(id, rating);

            //Kalla svo á repo á láta skila get á totalCount og total rating
            var totalRating = _bookRepo.GetTotalRating(id);
            var ratingCount = _bookRepo.GetRatingCount(id);

            //reikna svo út nýtt averageRating
            var newAverage = GetNewRating(totalRating, ratingCount);

            //Senda það svo ásamt bookId á repo til að gera update í grunninn
            _bookRepo.UpdateRating(id, newAverage);
        }