public async Task <IActionResult> SetPlayersMatch([FromBody] TwoIds json) { ulong firstId = json.WinnerId; ulong secondId = json.LoserId; string topic = json.Topic ?? Match.DefaultTopic; ulong guildId = json.GuildId; var firstPlayer = await PlayerController.GetPlayerWithId(firstId, context, includeMatches : true, readOnly : false); if (firstPlayer == null) { return(BadRequest()); } var secondPlayer = await PlayerController.GetPlayerWithId(secondId, context, includeOpponentMatches : true, readOnly : false); if (secondPlayer == null) { return(BadRequest()); } List <Match> result = new List <Match> (); result.Add(await MatchController.GetPlayerMatch(firstPlayer, secondPlayer, context, topic, guildId)); result.Add(await MatchController.GetPlayerMatch(secondPlayer, firstPlayer, context, topic, guildId)); foreach (var r in result) { r.PendingFight = true; } context.SaveChanges(); return(Ok(result)); }
public async Task <IActionResult> CompletePlayersMatch([FromBody] TwoIds json) { ulong id1 = json.WinnerId; ulong id2 = json.LoserId; string topic = json.Topic ?? Match.DefaultTopic; ulong guildId = json.GuildId; var winner = await PlayerController.GetPlayerWithId(id1, context, includeMatches : true, readOnly : false); if (winner == null) { return(BadRequest()); } var loser = await PlayerController.GetPlayerWithId(id2, context, readOnly : false); if (loser == null) { return(BadRequest()); } var results = await GetCompletePlayerMatch(context, winner, loser, topic, guildId); var winnerResult = results[0]; var loserResult = results[1]; if (winnerResult == null || loserResult == null) { return(BadRequest("Match has not been set to start.")); } if (!winnerResult.PendingFight || !loserResult.PendingFight) { return(BadRequest("No match is pending")); } await CompletePlayerMatch(context, winnerResult, loserResult); return(Ok(winnerResult)); }