/// <summary> /// Finds and sets a toplocation /// </summary> public void SetTopLocations() { List <Location> allLocations = GetAllLocations(); int allHits = 0; foreach (var location in allLocations) { allHits += location.Hits; } foreach (var location in allLocations) { bool oldIsTopLocation = location.IsTopLocation; location.IsTopLocation = false; double averageRating = 0; foreach (var rating in location.Ratings) { averageRating += rating.Rate; } if (location.Ratings.Count > 0) { averageRating = averageRating / location.Ratings.Count; } if (location.Hits > allHits / 10000 || location.Hits > 1000 && averageRating >= 4.5 || location.Hits > 10000 && averageRating >= 4 || location.Ratings.Count > 100 && averageRating >= 4.5) { location.IsTopLocation = true; } if (oldIsTopLocation != location.IsTopLocation) { _dbLocation.UpdateLocationAsTopLocation(location); } } }