public static IEnumerable <Scores> GetScores( SoraDbContextFactory factory, string fileMd5, Users user, PlayMode playMode = PlayMode.Osu, bool relaxing = false, bool friendsOnly = false, bool countryOnly = false, bool modOnly = false, Mod mods = Mod.None, bool onlySelf = false) { CountryIds cid = 0; if (countryOnly) { cid = UserStats.GetUserStats(factory, user.Id).CountryId; } var query = factory.Get().Scores .Where(score => score.FileMd5 == fileMd5 && score.PlayMode == playMode) .Where( score => relaxing ? (score.Mods & Mod.Relax) != 0 : (score.Mods & Mod.Relax) == 0 ) .Where( score => !friendsOnly || factory.Get().Friends .Where(f => f.UserId == user.Id) .Select(f => f.FriendId) .Contains(score.UserId) ) .Where( score => !countryOnly || factory.Get().UserStats .Select(c => c.CountryId) .Contains(cid) ) .Where(score => !modOnly || score.Mods == mods) .Where(score => !onlySelf || score.UserId == user.Id) .OrderByDescending(score => score.TotalScore) .GroupBy(s => s.UserId) .Take(50); IEnumerable <Scores> result = query.ToArray().Select(s => s.Select(xs => xs).First()).ToList(); foreach (var s in result) { s.Position = factory.Get().Scores .Where(score => score.FileMd5 == fileMd5 && score.PlayMode == playMode) .Where( score => relaxing ? (score.Mods & Mod.Relax) != 0 : (score.Mods & Mod.Relax) == 0 ) .OrderByDescending(score => score.TotalScore) .IndexOf(s) + 1; } return(result); }
// ReSharper disable once UnusedMember.Global public static string CountryIdToString(CountryIds x) => x.ToString();