public ITeam createTeam(ITeam entry)
        {
            ITeam team = TeamsTable.Create(entry, dbConn);

            if (team == null)
            {
                return(null);
            }

            team = TeamsTable.Get(team.TeamName, dbConn);
            if (team == null)
            {
                return(null);
            }

            entry.TeamId = team.TeamId;  //Quickfix for TeamsTable.Create() not setting the TeamId Correctly

            foreach (var participant in entry.TeamMembers)
            {
                TeamMembersTable.Create(new TeamMember()
                {
                    PersonId = participant.PersonId,
                    TeamId   = team.TeamId
                }, dbConn);
            }
            return(entry);
        }
 /// <summary>
 /// It only retrieves data when File changes. Uses Checksum validation to check if the file is different from last reading
 /// </summary>
 /// <returns>TeamMembersTable object</returns>
 private TeamMembersTable RetrieveData()
 {
     try
     {
         var assetPath = Path.Combine(Application.streamingAssetsPath, "JsonChallenge.json");
         if (!isReadingFile)
         {
             isReadingFile = true;
             var newChecksum = ComputeHash(assetPath);
             if (newChecksum != latestMd5)
             {
                 UnityEngine.Debug.Log("Change detected in file");
                 var jsonMembers = File.ReadAllText(assetPath);
                 jsonMembers      = Regex.Replace(jsonMembers, @"\,(?=\s*?[\}\]])", ""); //remove trailing commas in json (the example provided had this error)
                 teamsMemberTable = JsonUtility.FromJson <TeamMembersTable>(jsonMembers);
                 latestMd5        = newChecksum;
             }
             isReadingFile = false;
         }
     }
     catch (Exception ex)
     {
         UnityEngine.Debug.Log("There was a problem reading the file, maybe it was in use in another process: " + ex.Message);
         isReadingFile = false;
     }
     return(teamsMemberTable);
 }
    /// <summary>
    /// Render a TeamMembersTable
    /// </summary>
    /// <param name="teamData">Receives the team data to be rendered</param>
    private void Render(TeamMembersTable teamData)
    {
        //set colors
        _colorTitle        = new Color(1, 1, 1);
        _colorHeadingTable = new Color(0.8f, 0.8f, 0.8f);
        _colorContentTable = new Color(0.6f, 0.6f, 0.6f);

        //set font styles
        _headerFont = new GUIStyle();
        _titleFont  = new GUIStyle();
        _smallFont  = new GUIStyle();

        _titleFont.fontSize   = 18;
        _titleFont.alignment  = TextAnchor.MiddleCenter;
        _headerFont.fontSize  = 14;
        _headerFont.alignment = TextAnchor.MiddleCenter;
        _smallFont.fontSize   = 10;
        _smallFont.alignment  = TextAnchor.MiddleCenter;

        //set dedault texture and default style
        if (_defaultTexture == null)
        {
            _defaultTexture = new Texture2D(1, 1);
        }
        if (_defaultStyle == null)
        {
            _defaultStyle = new GUIStyle();
        }

        //calculate the horizontal space that one cell should use
        var horizontalSpace = Screen.width / teamData.ColumnHeaders.Count + 1;
        //fix height of cells in 30
        var verticalSpace = 30;

        //Draw title
        GUIDrawRect(new Rect(0, 0, Screen.width, verticalSpace * 2), _colorTitle, "Team Members", _titleFont);

        //Draw table headers
        for (int i = 0; i < teamData.ColumnHeaders.Count; i++)
        {
            GUIDrawRect(new Rect(i * horizontalSpace, verticalSpace * 2, horizontalSpace, verticalSpace), _colorHeadingTable, teamData.ColumnHeaders[i], _headerFont);
        }

        //draw table rows (members)
        for (int i = 0; i < teamData.Data.Count; i++)
        {
            GUIDrawRect(new Rect(0 * horizontalSpace, verticalSpace * (i + 3), horizontalSpace, verticalSpace), _colorContentTable, teamData.Data[i].ID, _smallFont);
            GUIDrawRect(new Rect(1 * horizontalSpace, verticalSpace * (i + 3), horizontalSpace, verticalSpace), _colorContentTable, teamData.Data[i].Name, _smallFont);
            GUIDrawRect(new Rect(2 * horizontalSpace, verticalSpace * (i + 3), horizontalSpace, verticalSpace), _colorContentTable, teamData.Data[i].Role, _smallFont);
            GUIDrawRect(new Rect(3 * horizontalSpace, verticalSpace * (i + 3), horizontalSpace, verticalSpace), _colorContentTable, teamData.Data[i].Nickname, _smallFont);
        }
    }
        public List <ITeam> getAllTeams()
        {
            var allTeams       = TeamsTable.GetAll(dbConn);
            var allTeamMembers = TeamMembersTable.GetAll(dbConn);
            var allPersons     = PersonsTable.GetAll(dbConn);

            foreach (var team in allTeams)
            {
                var members = allTeamMembers.Where(x => x.TeamId == team.TeamId);
                foreach (var person in members)
                {
                    var thePersonRecord = allPersons.Where(x => x.PersonId == person.PersonId).First();
                    team.TeamMembers.Add(thePersonRecord);
                }
            }

            return(allTeams);
        }
        public ITournament getTournament(int id)
        {
            var tournament           = TournamentTable.Get(id, dbConn);
            var allRounds            = RoundsTable.GetAll(dbConn);
            var allMatchups          = MatchupsTable.GetAll(dbConn);
            var allMatchupEntries    = MatchupEntriesTable.GetAll(dbConn);
            var allTournamentEntries = TournamentEntryTable.GetAll(dbConn);
            var allTeams             = TeamsTable.GetAll(dbConn);
            var allTeamMembers       = TeamMembersTable.GetAll(dbConn);
            var allPersons           = PersonsTable.GetAll(dbConn);
            var allTournamentPrizes  = TournamentPrizesTable.GetAll(dbConn);

            tournament.TournamentEntries = allTournamentEntries.Where(x => x.TournamentId == tournament.TournamentId).ToList();
            tournament.TournamentPrizes  = allTournamentPrizes.Where(x => x.TournamentId == tournament.TournamentId).ToList();

            foreach (var entry in tournament.TournamentEntries)
            {
                var entryMembers = allTeamMembers.Where(x => x.TeamId == entry.TeamId).ToList();
                foreach (var member in entryMembers)
                {
                    entry.Members.Add(allPersons.Find(x => x.PersonId == member.PersonId));
                }
                var theTeam = allTeams.Where(x => x.TeamId == entry.TeamId).First();
                tournament.Teams.Add(theTeam);
            }
            tournament.Rounds = allRounds.Where(x => x.TournamentId == tournament.TournamentId).ToList();
            foreach (var round in tournament.Rounds)
            {
                round.Matchups = allMatchups.Where(x => x.RoundId == round.RoundId).ToList();
                foreach (var matchup in round.Matchups)
                {
                    matchup.MatchupEntries = allMatchupEntries.Where(x => x.MatchupId == matchup.MatchupId).ToList();
                    foreach (var team in matchup.MatchupEntries)
                    {
                        team.TheTeam = tournament.TournamentEntries.Where(x => x.TournamentEntryId == team.TournamentEntryId).First();
                    }
                }
            }

            return(tournament);
        }
 public List <ITeamMember> getTeamMembersByTeamId(int teamId)
 {
     return(TeamMembersTable.GetTeamMembersByTeamId(teamId, dbConn));
 }
 void OnGUI()
 {
     teamsMemberTable = RetrieveData();
     Render(teamsMemberTable);
 }