public IActionResult Get([Required] string id) { int value = 0; IEnumerable <ChapterDTO> chapters = _chapterService.GetFanficChapters(id) ?? new List <ChapterDTO>(); foreach (var chapter in chapters) { IEnumerable <ChapterRatingDTO> ratings = _chapterRatingService.GetChapterRatings(id) ?? new List <ChapterRatingDTO>(); foreach (var rating in ratings) { value += rating.GivenRating; } } int count = chapters.Count(); if (count != 0) { value /= count; } return(Ok(new ChapterRatingValueModel { ratingValue = value })); }
private async Task DeleteChapterRatings(string id) { IEnumerable <ChapterRatingDTO> ratings = _chapterRatingService.GetChapterRatings(id); if (ratings == null) { return; } foreach (var rating in ratings) { await _chapterRatingService.Delete(rating.Id); } }