private async Task <RlUserStat> GetStatsFromDb(SteamModel.Player fromSteam) { RlUserStat rlUserStats = null; long steamId = long.Parse(fromSteam.steamid); using (var db = new NinjaBotEntities()) { rlUserStats = db.RlUserStats.Where(r => r.SteamID == steamId).FirstOrDefault(); } return(rlUserStats); }
private async Task InsertStats(UserStats stats) { long steamId = long.Parse(stats.uniqueId); using (var db = new NinjaBotEntities()) { var statAdd = new RlUserStat(); var getStat = db.RlUserStats.Where(s => s.SteamID == steamId).FirstOrDefault(); if (stats.rankedSeasons._6._onevone != null) { statAdd.RankedDuel = stats.rankedSeasons._6._onevone.RankPoints.ToString(); } if (stats.rankedSeasons._6._twovtwo != null) { statAdd.Ranked2v2 = stats.rankedSeasons._6._twovtwo.RankPoints.ToString(); } if (stats.rankedSeasons._6._solostandard != null) { statAdd.RankedSolo = stats.rankedSeasons._6._solostandard.RankPoints.ToString(); } if (stats.rankedSeasons._6._standard != null) { statAdd.Ranked3v3 = stats.rankedSeasons._6._standard.RankPoints.ToString(); } if (getStat == null) { statAdd.SteamID = steamId; db.RlUserStats.Add(statAdd); } else { if (stats.rankedSeasons._6._onevone != null) { getStat.RankedDuel = stats.rankedSeasons._6._onevone.RankPoints.ToString(); } if (stats.rankedSeasons._6._twovtwo != null) { getStat.Ranked2v2 = stats.rankedSeasons._6._twovtwo.RankPoints.ToString(); } if (stats.rankedSeasons._6._solostandard != null) { getStat.RankedSolo = stats.rankedSeasons._6._solostandard.RankPoints.ToString(); } if (stats.rankedSeasons._6._standard != null) { getStat.Ranked3v3 = stats.rankedSeasons._6._standard.RankPoints.ToString(); } getStat.SteamID = steamId; } await db.SaveChangesAsync(); } }
private async Task InsertStats(List <RocketLeagueStats> stats, SteamModel.Player fromSteam) { long steamId = long.Parse(fromSteam.steamid); using (var db = new NinjaBotEntities()) { var statAdd = new RlUserStat(); var getStat = db.RlUserStats.Where(s => s.SteamID == steamId).FirstOrDefault(); var doubles = stats.Where(s => s.Title == "Doubles 2v2").FirstOrDefault(); var duel = stats.Where(s => s.Title == "Duel 1v1").FirstOrDefault(); var soloStandard = stats.Where(s => s.Title == "Solo Standard 3v3").FirstOrDefault(); var rankedThrees = stats.Where(s => s.Title == "Standard 3v3").FirstOrDefault(); var unranked = stats.Where(s => s.Title == "Unranked").FirstOrDefault(); if (getStat == null) { if (doubles != null) { statAdd.Ranked2v2 = doubles.MMR.ToString(); } else { statAdd.Ranked2v2 = "0"; } if (duel != null) { statAdd.RankedDuel = duel.MMR.ToString(); } else { statAdd.RankedDuel = "0"; } if (soloStandard != null) { statAdd.RankedSolo = soloStandard.MMR.ToString(); } else { statAdd.RankedSolo = "0"; } if (rankedThrees != null) { statAdd.Ranked3v3 = rankedThrees.MMR.ToString(); } else { statAdd.Ranked3v3 = "0"; } if (unranked != null) { statAdd.Unranked = unranked.MMR.ToString(); } else { statAdd.Unranked = "0"; } statAdd.SteamID = steamId; db.RlUserStats.Add(statAdd); } else { if (doubles != null) { getStat.Ranked2v2 = doubles.MMR.ToString(); } if (duel != null) { getStat.RankedDuel = duel.MMR.ToString(); } if (soloStandard != null) { getStat.RankedSolo = soloStandard.MMR.ToString(); } if (rankedThrees != null) { getStat.Ranked3v3 = rankedThrees.MMR.ToString(); } if (unranked != null) { getStat.Unranked = unranked.MMR.ToString(); } getStat.SteamID = steamId; } await db.SaveChangesAsync(); } }