//extract Max rating or return 0; public int GetMaxRating(int id) { int maxRating; using (var db = new SWratingsContext()) { // identify max rating if ther is one... // filter ratings for id ... var entities = from b in db.Ratings where b.CharacterId == id select b; // query max. if (entities.Any()) { maxRating = entities.Max(p => p.CharacterRating); } else { maxRating = 1; } } return((maxRating > 0) ? maxRating : 1); }
//constructor , initializa cache public CharacterController(IExternalService swapiService, IRatingService ratingService, SWratingsContext context, SWCharacterMemoryCache memoryCache) { _context = context; _swapiService = swapiService; _ratingService = ratingService; _cache = memoryCache.Cache; }
public RatingService(SWratingsContext context) { _context = context; }