public IActionResult MyProfile() //displays your profile. finds both your user and gamer and combines them to send to the view { string id = User.FindFirst(ClaimTypes.NameIdentifier).Value; Users foundUser = _context.Users.Where(x => x.UserId == id).First(); Gamers foundGamer = _context.Gamers.Where(x => x.UserId == id && x.Gamertag == foundUser.Gamertag).First(); UsersGamers UserProfile = new UsersGamers(foundUser, foundGamer); return(View(UserProfile)); }
public async Task <ActionResult> GetPlayerBySearch(string search) //searches for player, checks if it's valid and returns view with gamer { if (search == null) { string id = User.FindFirst(ClaimTypes.NameIdentifier).Value; ViewBag.Gamertag = _context.Users.Where(x => x.UserId == id).First().Gamertag; List <Gamers> userGamers = GetGamerList(); ViewBag.Message = "This gamertag does not exist"; return(View("DisplayGamers", userGamers)); } var client = new HttpClient(); client.BaseAddress = new Uri($"https://www.haloapi.com/stats/h5/servicerecords/arena"); client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", $"{APIKEYVARIABLE}"); var response = await client.GetAsync($"?players={search}"); var searchedPlayer = await response.Content.ReadAsAsync <PlayerRootObject>(); ViewBag.UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value; Gamers searchedGamer = new Gamers(searchedPlayer, 0); if (searchedGamer.Gamertag == null) { string id = User.FindFirst(ClaimTypes.NameIdentifier).Value; Users foundUser = _context.Users.Where(x => x.UserId == id).First(); Gamers foundGamer = _context.Gamers.Where(x => x.UserId == id && x.Gamertag == foundUser.Gamertag).First(); UsersGamers UserProfile = new UsersGamers(foundUser, foundGamer); ViewBag.Message = "This Gamertag does not exist, please try again!"; return(View("MyProfile", UserProfile)); } else if (searchedGamer.TotalTimePlayed == "") { string id = User.FindFirst(ClaimTypes.NameIdentifier).Value; Users foundUser = _context.Users.Where(x => x.UserId == id).First(); Gamers foundGamer = _context.Gamers.Where(x => x.UserId == id && x.Gamertag == foundUser.Gamertag).First(); UsersGamers UserProfile = new UsersGamers(foundUser, foundGamer); ViewBag.Message = "This Gamertag does not have any Halo 5 play time!"; return(View("MyProfile", UserProfile)); } return(View(searchedGamer)); }