public Response <EmptyResponse> UpdateMatch( TxSessionCredentials credentials, string bracketId, UpdateMatchRequest request) { return(bracketClient.UpdateMatch(credentials, bracketId, request)); }
public IActionResult UpdateMatch([Required] string bracketId, [Required] UpdateMatchRequest request) { var response = bracketService.UpdateMatch( requestFieldExtractor.ExtractTomUserSessionCredentials(), bracketId, request); return(Ok(response)); }
public async Task Update(int id, [FromBody] MatchDto match) { match.Id = id; var request = new UpdateMatchRequest { Match = match }; await _mediator.ExecuteAsync(request).ConfigureAwait(false); }
public Response <EmptyResponse> UpdateMatch( TxSessionCredentials credentials, string bracketId, UpdateMatchRequest request) { client.DefaultRequestHeaders.Add("UserId", credentials.UserId); client.DefaultRequestHeaders.Add("SessionId", credentials.SessionId); var response = client.PostAsync($"bracket/{bracketId}/match", RequestSerializer.Content(request)).Result; if (response.IsSuccessStatusCode) { return(Newtonsoft.Json.JsonConvert.DeserializeObject <Response <EmptyResponse> >(response.Content.ReadAsStringAsync().Result)); } return(new Response <EmptyResponse>(response.RequestMessage.ToString(), (int)response.StatusCode)); }
public MatchViewDto Put(UpdateMatchRequest request) { var matchToUpdate = Db.SingleById <Match>(request.Id); matchToUpdate.PopulateWith(request); if (matchToUpdate.HasResult && !matchToUpdate.ResultDate.HasValue) { matchToUpdate.ResultDate = DateTime.Now; } if (matchToUpdate.PlayDate.HasValue && !matchToUpdate.RegisterDate.HasValue) { matchToUpdate.ResultDate = matchToUpdate.PlayDate; } matchToUpdate.IsNotPlayedMatch = false; Db.Save(matchToUpdate); StandingsCalculator.Calculate(this.Db, matchToUpdate.LeagueId); return(Db.SingleById <MatchView>(request.Id).ConvertTo <MatchViewDto>()); }
public async Task UpdateMatchAsync( UpdateMatchRequest request, CancellationToken cancellationToken = default) { try { if (request == null) { throw new ArgumentNullException(nameof(request)); } Entities.Match entity = await _context.Matches .FirstOrDefaultAsync(t => t.Id == request.MatchId); if (entity == null) { throw new ObjectNotFoundException($"Match with Id: { request.MatchId } does not exist."); } if (request.Date == null) { throw new ArgumentException("Date cannot be null."); } if (request.IsSet(x => x.Date)) { if (request.Date > DateTime.Now) { throw new ArgumentException("Cannot register a match that is not yet played."); } entity.Date = request.Date; } if (request.IsSet(x => x.HomeTeamScore)) { entity.HomeTeamScore = request.HomeTeamScore; } if (request.IsSet(x => x.AwayTeamScore)) { entity.AwayTeamScore = request.AwayTeamScore; } int?newWinnerID = entity.AwayTeamScore > entity.HomeTeamScore ? entity.AwayTeamId : entity.AwayTeamScore < entity.HomeTeamScore ? entity.HomeTeamId : (int?)null; bool hasWinnerChanged = newWinnerID != entity.WinnerId; bool wasDraw = !entity.WinnerId.HasValue; if (hasWinnerChanged) { int?loserID = wasDraw ? (int?)null : entity.AwayTeamId != entity.WinnerId ? entity.AwayTeamId : entity.HomeTeamId; // If old result was draw, remove 1 point from each team if (wasDraw) { await UpdateTeamRankings(entity.AwayTeamId, -1); await UpdateTeamRankings(entity.HomeTeamId, -1); } // If new result is draw, remove 2 points from old winner and add 1 point to other team, so both earn 1 point else if (entity.HomeTeamScore == entity.AwayTeamScore) { await UpdateTeamRankings(entity.WinnerId.Value, -2); await UpdateTeamRankings(loserID.Value, 1); } // If new result is not draw, remove 3 points from previous winner and add 3 points to new winner else { await UpdateTeamRankings(entity.WinnerId.Value, -3); await UpdateTeamRankings(loserID.Value, 3); } // Set new winner Id entity.WinnerId = newWinnerID; } await _context.SaveChangesAsync(cancellationToken); } catch (ServiceException) { throw; } catch (Exception ex) { _logger.LogError(ex, "Error updating match."); throw Conversion.ConvertException(ex); } }