/// <summary> /// /// </summary> /// <param name="members"></param> /// <param name="leaderboardType"></param> /// <param name="take"></param> /// <returns></returns> public static IEnumerable <PartyHost> GetTopPartyHosts(this MembershipHelper members, LeaderboardType leaderboardType, int take) { List <PartyHost> partyHosts = new List <PartyHost>(); PartyHost partyHost = null; DatabaseContext databaseContext = ApplicationContext.Current.DatabaseContext; switch (leaderboardType) { case LeaderboardType.MostGuests: foreach (dynamic mostGuest in databaseContext.Database.Fetch <dynamic>(@" SELECT TOP " + take + @" PartyGuid, COUNT(MemberId) AS Partiers FROM wonderlandMemberParty GROUP BY PartyGuid ORDER BY Partiers DESC ")) { partyHost = members.GetPartyHost((Guid)mostGuest.PartyGuid); if (partyHost != null) { partyHost.TotalGuests = mostGuest.Partiers; partyHosts.Add(partyHost); } else { LogHelper.Error(typeof(MembershipHelperExtensions), "GetTopPartyHosts", new Exception("Host with party guid: " + ((Guid)mostGuest.PartyGuid).ToString() + " not found in Examine")); } } break; case LeaderboardType.TopFundraisers: foreach (dynamic topFundraiser in databaseContext.Database.Fetch <dynamic>(@" SELECT TOP " + take + @" PartyGuid, SUM(Amount) AS Amount FROM wonderlandDonation WHERE Success = 1 GROUP BY PartyGuid ORDER BY Amount DESC ")) { partyHost = members.GetPartyHost((Guid)topFundraiser.PartyGuid); if (partyHost != null) { partyHost.AmountRaised = topFundraiser.Amount; partyHosts.Add(partyHost); } else { LogHelper.Error(typeof(MembershipHelperExtensions), "GetTopPartyHosts", new Exception("Host with party guid: " + ((Guid)topFundraiser.PartyGuid).ToString() + " not found in Examine")); } } break; } return(partyHosts); }