private void UpdateThirdLevelDataByTeam(Team team, GetTeamScheduleTotals_Result result)
        {
            try
            {
                if ( result.TotalRatingPointsThirdLevel != null )
                {
                    // Rating Points Third Level total and average
                    team.RatingPointsThirdLevel = (decimal)result.TotalRatingPointsThirdLevel;
                    team.RatingPointsThirdLevelAverage = Arithmetic.Divide(team.RatingPointsThirdLevel, team.RatingPointGames);

                    lock ( _dbLock )
                    {
                        DataAccess.DbContext.SaveChanges();
                    }
                }
            }
            catch ( InvalidOperationException ex )
            {
                if ( ex.Message == "Nullable object must have a value." )
                {
                    // Ignore exception.
                }
                else
                {
                    Globals.ShowExceptionMessage(ex, "InvalidOperationException - " + team.Name);
                }
            }
            catch ( Exception ex )
            {
                Globals.ShowExceptionMessage(ex, "Exception - " + team.Name);
            }
        }
        private void UpdateFinalScoringDataByTeam(Team team, GetTeamScheduleTotals_Result result)
        {
            try
            {
                if ( result.ScheduleTotalGames != null )
                {
                    Classification classification;

                    lock ( _dbLock )
                    {
                        classification = (from c in DataAccess.DbContext.Classifications
                                                where c.Name == team.ClassificationName
                                                select c)
                                                .FirstOrDefault();
                    }

                    team.FinalOffensiveAverage = Arithmetic.Divide(
                         team.InClassificationAdjustedPointsFor * (decimal)result.ScheduleTotalGames
                         * classification.TotalAdjustedPointsFor * team.InClassificationGames
                         + team.InClassificationGames * (decimal)result.ScheduleTotalAdjustedPointsAgainst
                         * classification.TotalGames * team.OutOfClassificationAdjustedPointsFor,
                         team.InClassificationGames * (decimal)result.ScheduleTotalAdjustedPointsAgainst
                         * classification.TotalGames * team.Games);
                    team.FinalDefensiveAverage = Arithmetic.Divide(
                         team.InClassificationAdjustedPointsAgainst * (decimal)result.ScheduleTotalGames
                         * classification.TotalAdjustedPointsFor * team.InClassificationGames
                         + team.InClassificationGames * (decimal)result.ScheduleTotalAdjustedPointsFor
                         * classification.TotalGames * team.OutOfClassificationAdjustedPointsAgainst,
                         team.InClassificationGames * (decimal)result.ScheduleTotalAdjustedPointsFor
                         * classification.TotalGames * team.Games);
                    team.FinalOffensiveFactor = Arithmetic.Divide(
                         team.InClassificationAdjustedPointsFor * (decimal)result.ScheduleTotalGames,
                         team.InClassificationGames * (decimal)result.ScheduleTotalFinalAdjustedPointsAgainst);
                    team.FinalDefensiveFactor = Arithmetic.Divide(
                         team.InClassificationAdjustedPointsAgainst * (decimal)result.ScheduleTotalGames,
                         team.InClassificationGames * (decimal)result.ScheduleTotalFinalAdjustedPointsFor);
                    team.FinalOffensiveIndex
                        = (team.FinalOffensiveAverage + team.FinalOffensiveFactor * classification.AverageAdjustedPointsFor) / 2;
                    team.FinalDefensiveIndex
                        = (team.FinalDefensiveAverage + team.FinalDefensiveFactor * classification.AverageAdjustedPointsFor) / 2;
                    team.FinalScoringRatio = Arithmetic.Divide(
                        (decimal)team.FinalOffensiveIndex, (decimal)team.FinalOffensiveIndex + (decimal)team.FinalDefensiveIndex);

                    lock ( _dbLock )
                    {
                        DataAccess.DbContext.SaveChanges();
                    }
                }
            }
            catch ( InvalidOperationException ex )
            {
                if ( ex.Message == "Nullable object must have a value." )
                {
                    // Ignore exception.
                }
                else
                {
                    Globals.ShowExceptionMessage(ex, "InvalidOperationException - " + team.Name);
                }
            }
            catch ( Exception ex )
            {
                Globals.ShowExceptionMessage(ex, "Exception - " + team.Name);
            }
        }