public async Task <IActionResult> Create([FromBody] GameSession gameSession) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = await userRepository.GetUserAsync(User.Identity.Name); if (user == null) { return(NotFound(new { Message = "An error occurred while retrieving the user." })); } gameSession.User = user; await gameSessionRepository.AddGameSessionAsync(gameSession); return(Ok(gameSession)); }