private void UpdateFactionStats(int gameIdentID) { using (DataAccess.CSSStatsDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSStatsDataContext()) { var game = db.Games.FirstOrDefault(p => p.GameIdentID == gameIdentID); if (game == null) { throw new Exception("Couldn't get game for ID: " + gameIdentID); } if (IsGameEligibleForLogging(game) == false) { return; } if (IsDrawGame(game) == true) { return; } if (game.GameTeams.Count != 2) { return; } DataAccess.GameTeam winningTeam; DataAccess.GameTeam losingTeam; if (game.GameTeams[0].GameTeamWinner == true) { winningTeam = game.GameTeams[0]; losingTeam = game.GameTeams[1]; } else { winningTeam = game.GameTeams[1]; losingTeam = game.GameTeams[0]; } DataAccess.StatsFaction statsFaction = db.StatsFactions.FirstOrDefault(p => p.WinFactionName == winningTeam.GameTeamFaction && p.WinExpansion == winningTeam.GameTeamExpansion && p.WinShipyard == winningTeam.GameTeamShipyard && p.WinStarbase == winningTeam.GameTeamStarbase && p.WinSupremacy == winningTeam.GameTeamSupremacy && p.WinTactical == winningTeam.GameTeamTactical && p.LossFactionName == losingTeam.GameTeamFaction && p.LossExpansion == losingTeam.GameTeamExpansion && p.LossShipyard == losingTeam.GameTeamShipyard && p.LossStarbase == losingTeam.GameTeamStarbase && p.LossSupremacy == losingTeam.GameTeamSupremacy && p.LossTactical == losingTeam.GameTeamTactical ); if (statsFaction == null) { statsFaction = new Allegiance.CommunitySecuritySystem.DataAccess.StatsFaction() { GamesPlayed = 1, HoursPlayed = game.GameEndTime.Subtract(game.GameStartTime).TotalMinutes / 60, LossExpansion = losingTeam.GameTeamExpansion, LossFactionName = losingTeam.GameTeamFaction, LossShipyard = losingTeam.GameTeamShipyard, LossStarbase = losingTeam.GameTeamStarbase, LossSupremacy = losingTeam.GameTeamSupremacy, LossTactical = losingTeam.GameTeamTactical, WinExpansion = winningTeam.GameTeamExpansion, WinFactionName = winningTeam.GameTeamFaction, WinShipyard = winningTeam.GameTeamShipyard, WinStarbase = winningTeam.GameTeamStarbase, WinSupremacy = winningTeam.GameTeamSupremacy, WinTactical = winningTeam.GameTeamTactical, DateModified = DateTime.Now }; db.StatsFactions.InsertOnSubmit(statsFaction); } else { statsFaction.GamesPlayed++; statsFaction.HoursPlayed += game.GameEndTime.Subtract(game.GameStartTime).TotalMinutes / 60; statsFaction.DateModified = DateTime.Now; } db.SubmitChanges(); } }
private void UpdateFactionStats(int gameIdentID) { using (DataAccess.CSSStatsDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSStatsDataContext()) { var game = db.Games.FirstOrDefault(p => p.GameIdentID == gameIdentID); if (game == null) throw new Exception("Couldn't get game for ID: " + gameIdentID); if (IsGameEligibleForLogging(game) == false) return; if (IsDrawGame(game) == true) return; if(game.GameTeams.Count != 2) return; DataAccess.GameTeam winningTeam; DataAccess.GameTeam losingTeam; if(game.GameTeams[0].GameTeamWinner == true) { winningTeam = game.GameTeams[0]; losingTeam = game.GameTeams[1]; } else { winningTeam = game.GameTeams[1]; losingTeam = game.GameTeams[0]; } DataAccess.StatsFaction statsFaction = db.StatsFactions.FirstOrDefault(p => p.WinFactionName == winningTeam.GameTeamFaction && p.WinExpansion == winningTeam.GameTeamExpansion && p.WinShipyard == winningTeam.GameTeamShipyard && p.WinStarbase == winningTeam.GameTeamStarbase && p.WinSupremacy == winningTeam.GameTeamSupremacy && p.WinTactical == winningTeam.GameTeamTactical && p.LossFactionName == losingTeam.GameTeamFaction && p.LossExpansion == losingTeam.GameTeamExpansion && p.LossShipyard == losingTeam.GameTeamShipyard && p.LossStarbase == losingTeam.GameTeamStarbase && p.LossSupremacy == losingTeam.GameTeamSupremacy && p.LossTactical == losingTeam.GameTeamTactical ); if(statsFaction == null) { statsFaction = new Allegiance.CommunitySecuritySystem.DataAccess.StatsFaction() { GamesPlayed = 1, HoursPlayed = game.GameEndTime.Subtract(game.GameStartTime).TotalMinutes / 60, LossExpansion = losingTeam.GameTeamExpansion, LossFactionName = losingTeam.GameTeamFaction, LossShipyard = losingTeam.GameTeamShipyard, LossStarbase = losingTeam.GameTeamStarbase, LossSupremacy = losingTeam.GameTeamSupremacy, LossTactical = losingTeam.GameTeamTactical, WinExpansion = winningTeam.GameTeamExpansion, WinFactionName = winningTeam.GameTeamFaction, WinShipyard = winningTeam.GameTeamShipyard, WinStarbase = winningTeam.GameTeamStarbase, WinSupremacy = winningTeam.GameTeamSupremacy, WinTactical = winningTeam.GameTeamTactical, DateModified = DateTime.Now }; db.StatsFactions.InsertOnSubmit(statsFaction); } else { statsFaction.GamesPlayed++; statsFaction.HoursPlayed += game.GameEndTime.Subtract(game.GameStartTime).TotalMinutes / 60; statsFaction.DateModified = DateTime.Now; } db.SubmitChanges(); } }