private MatchViewModel GetMatchViewModel(MatchServiceModel model, ResultEnum?result = null) { return(new MatchViewModel { HomeTeam = model.HomeTeam, AwayTeam = model.AwayTeam, AwayWinPoints = model.AwayWinPoints, DrawPoints = model.DrawPoints, HomeWinPoints = model.HomeWinPoints, Id = model.Id, UserPrediction = result }); }
public async Task EditAsync(MatchServiceModel match) { var m = await this._dbContext .Matches .Where(m => m.Id == match.Id) .FirstOrDefaultAsync(); m.HomeGoals = match.HomeGoals; m.AwayGoals = match.AwayGoals; var homeTeam = await this._dbContext .Fixtures .Where(f => f.TeamId == m.HomeTeamId) .FirstOrDefaultAsync(); var awayTeam = await this._dbContext .Fixtures .Where(f => f.TeamId == m.AwayTeamId) .FirstOrDefaultAsync(); homeTeam.PlayedMatches++; awayTeam.PlayedMatches++; if (match.HomeGoals > match.AwayGoals) { homeTeam.Points += 3; homeTeam.Win += 1; awayTeam.Loss += 1; } else if (match.HomeGoals < match.AwayGoals) { awayTeam.Points += 3; awayTeam.Win += 1; homeTeam.Loss += 1; } else { awayTeam.Points += 1; homeTeam.Points += 1; awayTeam.Drawn += 1; homeTeam.Drawn += 1; } await this._dbContext.SaveChangesAsync(); }