// GET: Metrics/Champion/5 public ActionResult Champion(string id) { SummonerViewModel model = GetSummonerViewModel(); int SelectedChampionId; // No SelectedChampion, load all stats if (string.IsNullOrEmpty(id)) { //// TODO: Redirect to another action to show overall stats model.SelectedChampion = model.Summoner.Champions.FirstOrDefault(); } // Parse SelectedChampion as an ID else if (int.TryParse(id, out SelectedChampionId)) { model.SelectedChampion = model.Summoner.Champions.FirstOrDefault(c => c.ID == SelectedChampionId); } // Parse SelectedChampion as a champ name else { id = id.ToLowerInvariant(); model.SelectedChampion = model.Summoner.Champions.FirstOrDefault(c => c.Name.ToLowerInvariant() == id); } return(View(model)); }
//public ActionResult Champion(string Champion) //{ // return RedirectToAction("Champion", int.Parse(Champion)); //} private SummonerViewModel GetSummonerViewModel() { if (Session["Model"] == null) { SummonerViewModel summonerViewModel = new SummonerViewModel(); try { // Load XML via database XDocument SummonerMetrics = GetOnlineMetrics("GundayMonday"); // Load XML via local file //XDocument SummonerMetrics = GetOfflineMetrics("~/content/sample.xml"); summonerViewModel.Summoner = new SummonerModel(SummonerMetrics.Root.Element("Summoner")); } catch (Exception ex) { // TODO: Something useful summonerViewModel.Summoner = new SummonerModel(); } finally { HttpContext.Session.Add("Model", summonerViewModel); } } return(Session["Model"] as SummonerViewModel); }
public void GetSummonerInfo(string summonerName, string api, SummonerViewModel model) { var myApi = RiotApi.GetInstance(api); var staticApi = StaticRiotApi.GetInstance(api); if (summonerName != null) { GrabSummoner(myApi, summonerName, model); var champions = staticApi.GetChampions(Region.na, ChampionData.image).Champions.Values; var summonerSpells = staticApi.GetSummonerSpells(Region.na, SummonerSpellData.image).SummonerSpells.Values; var version = staticApi.GetVersions(Region.na).FirstOrDefault(); var rankedStats = myApi.GetStatsRanked(Region.na, model.SummonerId); var summonerIdList = new List <long> { model.SummonerId }; var leagues = myApi.GetLeagues(Region.na, summonerIdList).FirstOrDefault().Value; GrabEntries(leagues, model); GrabMatchHistory(myApi, model, version, champions, summonerSpells); model.Champions = champions; model.SummonerIcon = "http://ddragon.leagueoflegends.com/cdn/" + version + "/img/profileicon/" + model.SummonerIconId + ".png"; } }
public SummonerViewModel getDesiredSummoner(string username) { var summoner = this.Context.Summoners.FirstOrDefault(s => s.Username == username); SummonerViewModel summonerVm = Mapper.Map <Summoner, SummonerViewModel>(summoner); return(summonerVm); }
public ActionResult Summoner(string name) { name = "RiotSchmick"; IRiotGamesApi riot = new RiotGamesApi(_apikey); var summoner = riot.GetSummoner(name); SummonerViewModel summonerVm = _mapper.Map <SummonerViewModel>(summoner); return(View(summonerVm)); }
public ActionResult InviteToClub(SummonerViewModel model) { _context.ClubInvitations.Add(new ClubInvitation { FromId = model.coachId, ToId = model.UserId }); _context.SaveChanges(); return(RedirectToAction("Details", "Player", new { id = model.UserId })); }
public SummonerView(Summoner summoner) { InitializeComponent(); var vm = new SummonerViewModel { Navigation = Navigation, CurrentSummoner = summoner }; BindingContext = vm; }
public IActionResult LeagueofLegends(SummonerViewModel model) { if (model.SummonerName != null) { _summonerInfo.GetSummonerInfo(model.SummonerName, _config["ApiKey:Key"], model); return(View("LolStats", model)); } else { return(View(model)); } }
public void GrabSummoner(IRiotApi myApi, string summonerName, SummonerViewModel model) { try { var summoner = myApi.GetSummoner(Region.na, summonerName); model.SummonerName = summoner.Name; model.SummonerLevel = summoner.Level; model.SummonerRegion = summoner.Region; model.SummonerIconId = summoner.ProfileIconId; model.SummonerId = summoner.Id; } catch (RiotSharpException ex) { // Handle the exception however you want. Console.WriteLine("Could not get summoner or summoner does not exist"); return; } }
public void GrabEntries(List <League> leagues, SummonerViewModel model) { var allLeagues = new List <LeagueInfo>(); foreach (var league in leagues) { var leagueInfo = new LeagueInfo(); leagueInfo.Tier = league.Tier; leagueInfo.TierName = league.Name; leagueInfo.GameMode = league.Queue; leagueInfo.Wins = league.Entries.FirstOrDefault().Wins; leagueInfo.Losses = league.Entries.FirstOrDefault().Losses; leagueInfo.Division = league.Entries.FirstOrDefault().Division; leagueInfo.LeaguePoints = league.Entries.FirstOrDefault().LeaguePoints; leagueInfo.RankIcon = "/img/tier-icons/" + leagueInfo.Tier + "_" + leagueInfo.Division + ".png"; allLeagues.Add(leagueInfo); } model.League = allLeagues; }
public IActionResult LolStats(SummonerViewModel model) { return(View(model)); }
public ActionResult Details(string id) { var user = _context.Users.SingleOrDefault(u => u.Id == id); if (user == null) { return(HttpNotFound()); } if (user.UserTypeId == UserType.Coach) { return(View("Coach", user)); } var soloQueue = _context.RankedStats.SingleOrDefault(r => r.UserId == id && r.QueueType == "RANKED_SOLO_5x5"); var flexQueue = _context.RankedStats.SingleOrDefault(r => r.UserId == id && r.QueueType == "RANKED_FLEX_SR"); var matches = _context.MatchStatsNeeded.Where(m => m.UserId == id).ToList(); var mainRole = _context.Roles.SingleOrDefault(r => r.Id == user.RoleId); var champions = _context.Champions.ToList(); var role = _context.Roles.SingleOrDefault(x => x.Id == user.RoleId); //get average stats var list = matches.GroupBy(x => x.ChampionId).OrderByDescending(x => x.Count()).Take(5); //calculate EP for player if (user.EPoints == 0) { if (list.Count() >= 5) { // 2 dimentional array { champ id, kills, deaths, assists, minionskilled, visionScore } int[,] topArray = new int[5, 6] { { list.ElementAt(0).Key, 0, 0, 0, 0, 0 }, { list.ElementAt(1).Key, 0, 0, 0, 0, 0 }, { list.ElementAt(2).Key, 0, 0, 0, 0, 0 }, { list.ElementAt(3).Key, 0, 0, 0, 0, 0 }, { list.ElementAt(4).Key, 0, 0, 0, 0, 0 } }; var d = 0; // iterate and increment stats foreach (var champ in matches) { if (list.Where(x => x.Key == champ.ChampionId) != null) { for (var i = 0; i < topArray.GetLength(0); i++) { if (topArray[i, 0] == champ.ChampionId) { topArray[i, 1] += champ.Kills; topArray[i, 2] += champ.Deaths; topArray[i, 3] += champ.Assists; topArray[i, 4] += champ.TotalMinionsKilled; topArray[i, 5] += champ.VisionScore; } } } } // array contains average EPs {kills, assists, deaths, cs, vision } float[] aStats = new float[] { 0, 0, 0, 0, 0 }; //create average stats foreach (var item in list) { float aKills = (float)topArray[d, 1] / item.Count(); float aDeaths = (float)topArray[d, 2] / item.Count(); float aAssists = (float)topArray[d, 3] / item.Count(); float aMinionsKilled = (float)topArray[d, 4] / item.Count(); float aVision = (float)topArray[d, 5] / item.Count(); //get EP for this champ var ep = Global.GetEPoints(role.Name, aKills, aAssists, aDeaths, aMinionsKilled, aVision, soloQueue); //add it to array aStats[d] = ep; d++; } //back to 0 for next time d = 0; //get average EP float totalEP = 0; float EP; for (var x = 0; x < aStats.Length; x++) { totalEP += aStats[x]; } EP = totalEP / 5; user.EPoints = EP; } } var listOfInvitations = _context.ClubInvitations.ToList(); //view model var viewModel = new SummonerViewModel() { SummonerName = user.SummonerName, SoloQueue = soloQueue, FlexQueue = flexQueue, matches = matches, MainRole = mainRole.Name, Champions = champions, EP = user.EPoints, UserId = user.Id, Invitations = listOfInvitations }; _context.SaveChanges(); return(View(viewModel)); }
public IActionResult LeagueofLegends(SummonerViewModel model) { _summonerInfo.GetSummonerInfo(model.SummonerName, _config["ApiKey:Key"]); return(View()); }
public IActionResult Get(SummonerViewModel model, string summonerName) { _summonerInfo.GetSummonerInfo(summonerName, _config["ApiKey:Key"], model); return(Ok(model)); }
public void GrabMatchHistory(RiotApi myApi, SummonerViewModel model, string version, Dictionary <string, ChampionStatic> .ValueCollection champions, Dictionary <string, SummonerSpellStatic> .ValueCollection summonerSpells) { var matchHistory = myApi.GetRecentGames(Region.na, model.SummonerId);//stats var matches = new List <GameEntity>(); var match = 0; foreach (var game in matchHistory) { var theGame = new GameEntity(); theGame.Kills = game.Statistics.ChampionsKilled; theGame.Assist = game.Statistics.Assists; theGame.Deaths = game.Statistics.NumDeaths; theGame.win = game.Statistics.Win; double kda = (double)(game.Statistics.ChampionsKilled + game.Statistics.Assists) / (double)game.Statistics.NumDeaths; theGame.Kda = kda.ToString("0.##"); theGame.Map = game.MapType; theGame.ChampLevel = game.Level; theGame.GameMode = game.GameMode; theGame.GameType = game.GameType; theGame.GameSubType = game.GameSubType; var item0Id = game.Statistics.Item0; var item1Id = game.Statistics.Item1; var item2Id = game.Statistics.Item2; var item3Id = game.Statistics.Item3; var item4Id = game.Statistics.Item4; var item5Id = game.Statistics.Item5; var item6Id = game.Statistics.Item6; theGame.item0 = ConvertToImage("item", item0Id.ToString(), version); theGame.item1 = ConvertToImage("item", item1Id.ToString(), version); theGame.item2 = ConvertToImage("item", item2Id.ToString(), version); theGame.item3 = ConvertToImage("item", item3Id.ToString(), version); theGame.item4 = ConvertToImage("item", item4Id.ToString(), version); theGame.item5 = ConvertToImage("item", item5Id.ToString(), version); theGame.item6 = ConvertToImage("item", item6Id.ToString(), version); var players = game.FellowPlayers; var theFellowSummoners = new List <FellowSummoner>(); foreach (var summoner in players) { var theTeam = new FellowSummoner(); theTeam.teamId = summoner.TeamId; var champPlayedId = summoner.ChampionId; var champ = champions.Where(x => x.Id == champPlayedId).First(); var image = champ.Image.Full; theTeam.champImg = ConvertToImage("champion", image, version); theTeam.champName = champ.Name; theFellowSummoners.Add(theTeam); } theGame.inGameSummonerName = theFellowSummoners; var champId = game.ChampionId; var champPlayed = champions.Where(x => x.Id == champId).First(); theGame.ChampName = champPlayed.Name; var champImage = champPlayed.Image.Full; theGame.ChampPicture = ConvertToImage("champion", champImage, version); var spell1Id = game.SummonerSpell1; var spell2Id = game.SummonerSpell2; var spell1 = summonerSpells.Where(x => x.Id == spell1Id).First().Image.Full; var spell2 = summonerSpells.Where(x => x.Id == spell2Id).First().Image.Full; theGame.SummonerSpell1 = ConvertToImage("spell", spell1, version); theGame.SummonerSpell2 = ConvertToImage("spell", spell2, version); matches.Add(theGame); match++; } model.MatchList = matches; }