public async Task <IActionResult> AddGameAsync(VideoGame game) { if (ModelState.IsValid) { if (game.Id == -1) { game.Id = null; } game.OwnerId = User.FindFirstValue(ClaimTypes.NameIdentifier); //Test if image is real. If it is not, use placeholder image try { using var client = new HttpClient(); var result = await client.GetAsync(game.ImgSrc); //Console.WriteLine(result.Content.Headers.ContentType); if (!result.Content.Headers.ContentType.ToString().Contains("image")) { game.ImgSrc = "/img/noImage.png"; } } catch (Exception e) { //Link does not lead anywhere //set default image game.ImgSrc = "/img/noImage.png"; } dataAccessLayer.AddGame(game); return(Redirect("~/Collection/Index")); } return(View("GameForm")); }