private void AddIdentifiersToRegisteredTags(IEnumerable<string[]> matchedPlayers) { foreach (var matchedPlayer in matchedPlayers) { if (matchedPlayer.Length != 2) continue; var player = Database.Players.Add(new Player()); Database.SaveChanges(); var playerTag = new PlayerTag() { PlayerGameTag = matchedPlayer[0], PlayerId = player.PlayerId, IsCurrentTag = true }; Database.PlayerTags.Add(playerTag); Database.SaveChanges(); var playerIdentifier = new PlayerTagIdentifier { Identifier = matchedPlayer[1], PlayerTagsId = playerTag.PlayerTagsId }; Database.PlayerTagIdentifiers.Add(playerIdentifier); //databaseChanges = true; } Database.SaveChanges(); }
public string RegisterNewPlayer(string userName) { var registered = (Database.PlayerTags.FirstOrDefault(x => x.PlayerGameTag == userName) != null); if (registered) return string.Format("{0} has already been registered.", userName); var player = new Player(); player = Database.Players.Add(player); Database.SaveChanges(); var playerTag = new PlayerTag { PlayerGameTag = userName, IsCurrentTag = true, Player = player, PlayerId = player.PlayerId }; Database.PlayerTags.Add(playerTag); Database.SaveChanges(); return "success"; }
private TournamentDataModel ReplaceUnmatchedIds(TournamentDataModel model, List<PlayerTag> playerTags, IEnumerable<string[]> unmatchedPlayers) { var playerTag = new PlayerTag(); foreach (var unmatchedPlayer in unmatchedPlayers) { playerTag = ReplaceChallongeIdWithPlayerTag(playerTags, unmatchedPlayer[0]); model.Participants .Single(x => x.participant.display_name == playerTag.PlayerGameTag) .participant.tournament_id = playerTag.PlayerId; } return model; }
private TournamentDataModel ReplaceMatchedIds(TournamentDataModel model, List<PlayerTag> playerTags, IEnumerable<string[]> matchedPlayers) { var playerTag = new PlayerTag(); foreach (var matchedPlayer in matchedPlayers) { if (matchedPlayer.Length == 1) playerTag = ReplaceChallongeIdWithPlayerTag(playerTags, matchedPlayer[0]); else if(matchedPlayer.Length == 2) playerTag = ReplaceMatchedAssociatedId(playerTags, matchedPlayer); else playerTag = ReplaceMatchedAssociatedById(playerTags, matchedPlayer[2]); model.Participants .Single(x => x.participant.display_name == playerTag.PlayerGameTag) .participant.tournament_id = playerTag.PlayerId; } return model; }
private void AssociateUnmatchedPlayer(IEnumerable<string[]> unmatchedPlayers) { var playerTagsList = Database.PlayerTags.ToList(); foreach (var unmatchedPlayer in unmatchedPlayers) { if (unmatchedPlayer.Count() == 1) continue; var name = unmatchedPlayer[1]; var playerToAssociateTo = playerTagsList.Single(x => x.PlayerTagIdentifiers.ToTagsAndIdentifierString(x.PlayerGameTag) == name); var player = new PlayerTag() { PlayerGameTag = unmatchedPlayer[0], PlayerId = playerToAssociateTo.PlayerId, IsCurrentTag = false }; Database.PlayerTags.Add(player); } Database.SaveChanges(); }
private void SaveUnmatchedPlayers(IEnumerable<string[]> unmatchedPlayers, int tournamentId) { foreach (var unmatchedPlayer in unmatchedPlayers) { if (HasAdditionalIdentifiers(unmatchedPlayer)) continue; var playerToAssociateTo = _glickoHelper.CreateNewPlayer(tournamentId); var playerTag = new PlayerTag() { PlayerGameTag = unmatchedPlayer[0], PlayerId = playerToAssociateTo.PlayerId, IsCurrentTag = true }; Database.PlayerTags.Add(playerTag); } Database.SaveChanges(); }