// TODO Refactor this method. private async Task <string> AssignGuildMemberRank(IWarcraftClient warcraftClient, Token token) { // We retrieve a list of all our Guild Members. List <GuildMember> warcraftGuildMembers = warcraftClient.GetGuildRosterAsync("draenor", "perplexed", "profile-eu") .Result.Value.Members.OrderBy(members => members.Rank) .ThenBy(members => members.Character.Name) .ToList(); Dictionary <int, int> keyValueForRanks = new Dictionary <int, int>(); for (int i = 0; i < warcraftGuildMembers.Count; i++) { keyValueForRanks.Add(warcraftGuildMembers[i].Character.Id, warcraftGuildMembers[i].Rank); } RequestResult <AccountProfileSummary> result = await warcraftClient.GetAccountProfileSummaryAsync(token.access_token, "profile-eu"); bool Member = false; if (result.Success) { var wowAccounts = result.Value.WowAccounts; foreach (ArgentPonyWarcraftClient.WowAccount account in wowAccounts) { foreach (ArgentPonyWarcraftClient.AccountCharacter character in account.Characters) { // The 2 refers to the ranks that exist in the guild. The API returns numbers. 0, 1 and 2 are officer ranks. if (keyValueForRanks.TryGetValue(character.Id, out int rankNumberOfficer) && rankNumberOfficer <= 2) { return("Officer"); } if (keyValueForRanks.TryGetValue(character.Id, out int rankNumberMember) && rankNumberMember >= 3) { Member = true; } } } if (Member) { return("Member"); } return("Guest"); } // User does not have a BattleNet account. return("Failure Profile"); }
/// <returns>A list of all guild members.</returns> public List <InstinctGuildMember> PrepareGuildMembersList() { List <GuildMember> warcraftGuildMembers = _warcraftClient.GetGuildRosterAsync("draenor", "perplexed", "profile-eu") .Result.Value.Members.OrderBy(members => members.Rank) .ThenBy(members => members.Character.Name) .ToList(); // We call the raceIndex and the classIndex here to reduce the total amount of API calls. PlayableRacesIndex raceIndex = _warcraftClient.GetPlayableRacesIndexAsync("static-eu").Result.Value; PlayableClassesIndex classIndex = _warcraftClient.GetPlayableClassesIndexAsync("static-eu").Result.Value; // We create a new list with our own model of InstinctGuildMembers List <InstinctGuildMember> instinctGuildMembers = new List <InstinctGuildMember>(); foreach (GuildMember member in warcraftGuildMembers) { InstinctGuildMember newModel = ConvertGuildMemberModel(member, classIndex, raceIndex); instinctGuildMembers.Add(newModel); } return(instinctGuildMembers); }