private async void SendHangmanWordToAPI(HangmanWordDTO wordDTO) { var game = JsonConvert.SerializeObject(wordDTO); HttpClient client = new HttpClient(); var res = await client.PutAsync("http://localhost:5000/api/Game/word", new StringContent(game, System.Text.Encoding.UTF8, "application/json")); RefreshGames(); }
public ActionResult SetWordForHangmanGame([FromBody] HangmanWordDTO dto) { try { return(Ok(GameService.SetWordForGame(dto))); } catch (ArgumentException) { return(NotFound()); } }
public bool SetWordForGame(HangmanWordDTO dto) { var game = (HangmanGame)games .Include(g => g.GamePair).ThenInclude(g => g.FirstGame).ThenInclude(g => g.Player) .Include(g => g.GamePair).ThenInclude(g => g.SecondGame).ThenInclude(g => g.Player) .SingleOrDefault(s => s.GameId == dto.GameId) ?? throw new ArgumentException(); game.SetWord(dto.Word); games.Update(game); context.SaveChanges(); return(true); }