public void DeleteSingleLeagueGoal(SingleLeagueGoalModel singleLeagueGoalModel) { if (singleLeagueGoalModel == null) { throw new ArgumentNullException(nameof(singleLeagueGoalModel)); } var matchToChange = _context.SingleLeagueMatches.Where(x => x.Id == singleLeagueGoalModel.MatchId).FirstOrDefault(); _context.SingleLeagueGoals.Remove(singleLeagueGoalModel); UpdateSingleLeagueMatchScore(matchToChange, singleLeagueGoalModel); _context.SaveChanges(); }
private void UpdateSingleLeagueMatchScore(SingleLeagueMatchModel matchToChange, SingleLeagueGoalModel singleLeagueGoalModel) { if (matchToChange.PlayerOne == singleLeagueGoalModel.ScoredByUserId) { if (matchToChange.PlayerOneScore > 0) { matchToChange.PlayerOneScore -= 1; } } if (matchToChange.PlayerTwo == singleLeagueGoalModel.ScoredByUserId) { if (matchToChange.PlayerTwoScore > 0) { matchToChange.PlayerTwoScore -= 1; } } _context.SingleLeagueMatches.Update(matchToChange); }