コード例 #1
0
ファイル: TaskController.cs プロジェクト: mpnieland/NPGGFFL2
        private bool UpdatePlayerStats(Stats playerStats, int gameTimeRemaining)
        {
            GameCenterController gController = new GameCenterController();
            var scDictionary = gController.BuildScoringConfigDictionary();

            var PassingYards = playerStats.Statistic.Where(s => s.StatType.Equals("Passing") && s.StatName.Equals("Yds")).FirstOrDefault();
            var PassingTDs = playerStats.Statistic.Where(s => s.StatType.Equals("Passing") && s.StatName.Equals("TDs")).FirstOrDefault();
            var RushingYards = playerStats.Statistic.Where(s => s.StatType.Equals("Rushing") && s.StatName.Equals("Yds")).FirstOrDefault();
            var RushingTDs = playerStats.Statistic.Where(s => s.StatType.Equals("Rushing") && s.StatName.Equals("TDs")).FirstOrDefault();
            var ReceivingReceptions = playerStats.Statistic.Where(s => s.StatType.Equals("Receiving") && s.StatName.Equals("Rec")).FirstOrDefault();
            var ReceivingYards = playerStats.Statistic.Where(s => s.StatType.Equals("Receiving") && s.StatName.Equals("Yds")).FirstOrDefault();
            var ReceivingTDs = playerStats.Statistic.Where(s => s.StatType.Equals("Receiving") && s.StatName.Equals("TDs")).FirstOrDefault();
            var TwoPointConversionsPassing = playerStats.Statistic.Where(s => s.StatType.Equals("Passing") && s.StatName.Equals("2PCs")).FirstOrDefault();
            var TwoPointConversionsRushing = playerStats.Statistic.Where(s => s.StatType.Equals("Rushing") && s.StatName.Equals("2PCs")).FirstOrDefault();
            var TwoPointConversionsReceiving = playerStats.Statistic.Where(s => s.StatType.Equals("Receiving") && s.StatName.Equals("2PCs")).FirstOrDefault();
            var DefensiveTDs = playerStats.Statistic.Where(s => s.StatType.Equals("Team Defense") && s.StatName.Equals("Defensive TDs")).FirstOrDefault();
            var KickReturnTDs = playerStats.Statistic.Where(s => s.StatType.Equals("Kick Return") && s.StatName.Equals("Kick Ret TDs")).FirstOrDefault();
            var PuntReturnTDs = playerStats.Statistic.Where(s => s.StatType.Equals("Punt Return") && s.StatName.Equals("Punt Ret TDs")).FirstOrDefault();
            var FieldGoalsMade = playerStats.Statistic.Where(s => s.StatType.Equals("Kicking") && s.StatName.Equals("FGs")).FirstOrDefault();
            var ExtraPointsMade = playerStats.Statistic.Where(s => s.StatType.Equals("Kicking") && s.StatName.Equals("XPs")).FirstOrDefault();
            var Safeties = playerStats.Statistic.Where(s => s.StatType.Equals("Team Defense") && s.StatName.Equals("Safeties")).FirstOrDefault();
            var PointsAllowed = playerStats.Statistic.Where(s => s.StatType.Equals("Team Defense") && s.StatName.Equals("Pts Allowed")).FirstOrDefault();
            var Points = playerStats.TotalPoints;
            var playerGame = context.Games.Where(g => g.GameId == playerStats.PlayerGameId).FirstOrDefault();

            var statsExist = context.PlayerStats.Where(ps => ps.PlayerId == playerStats.PlayerProfileId && ps.GameId == playerStats.PlayerGameId).FirstOrDefault();
            if (statsExist == null)
            {
                statsExist = new PlayerStat();
                statsExist.PlayerId = playerStats.PlayerProfileId;
                statsExist.PlayerName = playerStats.PlayerName;
                statsExist.GameId = playerStats.PlayerGameId;
                statsExist.GameDesc = string.Format("{0} vs. {1}", playerGame.AwayTeamId.ToUpper(), playerGame.HomeTeamId.ToUpper());
                statsExist.GameTimeRemaining = gameTimeRemaining;
                statsExist.PassingYards = (PassingYards == null ? 0 : Convert.ToInt32(PassingYards.StatValue));
                statsExist.PassingTDs = (PassingTDs == null ? 0 : Convert.ToInt32(PassingTDs.StatValue));
                statsExist.RushingYards = (RushingYards == null ? 0 : Convert.ToInt32(RushingYards.StatValue));
                statsExist.RushingTDs = (RushingTDs == null ? 0 : Convert.ToInt32(RushingTDs.StatValue));
                statsExist.ReceivingReceptions = (ReceivingReceptions == null ? 0 : Convert.ToInt32(ReceivingReceptions.StatValue));
                statsExist.ReceivingYards = (ReceivingYards == null ? 0 : Convert.ToInt32(ReceivingYards.StatValue));
                statsExist.ReceivingTDs = (ReceivingTDs == null ? 0 : Convert.ToInt32(ReceivingTDs.StatValue));
                statsExist.TwoPointConversions = (TwoPointConversionsPassing == null ? 0 : Convert.ToInt32(TwoPointConversionsPassing.StatValue)) + (TwoPointConversionsRushing == null ? 0 : Convert.ToInt32(TwoPointConversionsRushing.StatValue)) + (TwoPointConversionsReceiving == null ? 0 : Convert.ToInt32(TwoPointConversionsReceiving.StatValue));
                statsExist.DefensiveTDs = (DefensiveTDs == null ? 0 : Convert.ToInt32(DefensiveTDs.StatValue));
                statsExist.KickReturnTDs = (KickReturnTDs == null ? 0 : Convert.ToInt32(KickReturnTDs.StatValue));
                statsExist.PuntReturnTDs = (PuntReturnTDs == null ? 0 : Convert.ToInt32(PuntReturnTDs.StatValue));
                statsExist.FumbleRecoveryTDs = 0;
                statsExist.FieldGoalsMade = (FieldGoalsMade == null ? 0 : Convert.ToInt32(FieldGoalsMade.StatValue));
                statsExist.ExtraPointsMade = (ExtraPointsMade == null ? 0 : Convert.ToInt32(ExtraPointsMade.StatValue));
                statsExist.Safeties = (Safeties == null ? 0 : Convert.ToInt32(Safeties.StatValue));
                statsExist.PointsAllowed = (PointsAllowed == null ? 0 : Convert.ToInt32(PointsAllowed.StatValue));
                statsExist.Points = Points;

                context.PlayerStats.InsertOnSubmit(statsExist);
            }
            else
            {
                statsExist.GameTimeRemaining = gameTimeRemaining;
                statsExist.PassingYards = (PassingYards == null ? 0 : Convert.ToInt32(PassingYards.StatValue));
                statsExist.PassingTDs = (PassingTDs == null ? 0 : Convert.ToInt32(PassingTDs.StatValue));
                statsExist.RushingYards = (RushingYards == null ? 0 : Convert.ToInt32(RushingYards.StatValue));
                statsExist.RushingTDs = (RushingTDs == null ? 0 : Convert.ToInt32(RushingTDs.StatValue));
                statsExist.ReceivingReceptions = (ReceivingReceptions == null ? 0 : Convert.ToInt32(ReceivingReceptions.StatValue));
                statsExist.ReceivingYards = (ReceivingYards == null ? 0 : Convert.ToInt32(ReceivingYards.StatValue));
                statsExist.ReceivingTDs = (ReceivingTDs == null ? 0 : Convert.ToInt32(ReceivingTDs.StatValue));
                statsExist.TwoPointConversions = (TwoPointConversionsPassing == null ? 0 : Convert.ToInt32(TwoPointConversionsPassing.StatValue)) + (TwoPointConversionsRushing == null ? 0 : Convert.ToInt32(TwoPointConversionsRushing.StatValue)) + (TwoPointConversionsReceiving == null ? 0 : Convert.ToInt32(TwoPointConversionsReceiving.StatValue));
                statsExist.DefensiveTDs = (DefensiveTDs == null ? 0 : Convert.ToInt32(DefensiveTDs.StatValue));
                statsExist.KickReturnTDs = (KickReturnTDs == null ? 0 : Convert.ToInt32(KickReturnTDs.StatValue));
                statsExist.PuntReturnTDs = (PuntReturnTDs == null ? 0 : Convert.ToInt32(PuntReturnTDs.StatValue));
                statsExist.FumbleRecoveryTDs = 0;
                statsExist.FieldGoalsMade = (FieldGoalsMade == null ? 0 : Convert.ToInt32(FieldGoalsMade.StatValue));
                statsExist.ExtraPointsMade = (ExtraPointsMade == null ? 0 : Convert.ToInt32(ExtraPointsMade.StatValue));
                statsExist.Safeties = (Safeties == null ? 0 : Convert.ToInt32(Safeties.StatValue));
                statsExist.PointsAllowed = (PointsAllowed == null ? 0 : Convert.ToInt32(PointsAllowed.StatValue));
                statsExist.Points = Points;
            }

            context.SubmitChanges();                

            return true;
        }