private async void BtnSave_Click(object sender, EventArgs e) { if (ValidateChildren()) { try { if (DatePicker.Value > DateTime.Now.AddDays(2)) { if (CmbHomeClub.SelectedValue.ToString() == CmbAwayClub.SelectedValue.ToString()) { MessageBox.Show("You can't pick two same teams to play against each other.", "Information", MessageBoxButtons.OK); return; } var match = new Matches { HomeClubId = int.Parse(CmbHomeClub.SelectedValue.ToString()), AwayClubId = int.Parse(CmbAwayClub.SelectedValue.ToString()), DateGame = DatePicker.Value, IsFinished = false, StadiumId = StadiumId, GameStart = TimePicker.Value.ToString(), GameEnd = TimePicker.Value.AddHours(2).ToString(), LeagueId = int.Parse(CmbLeagues.SelectedValue.ToString()), SeasonId = SeasonId }; var addedMatch = await _aPIServiceMatch.Insert <Matches>(match); if (addedMatch != null) { var refereeMatch = new RefereeMatches { RefereeId = int.Parse(CmbReferees.SelectedValue.ToString()), MatchId = addedMatch.Id }; await _aPIServiceMatch.Insert <RefereeMatches>(refereeMatch, "RefereeMatch"); MessageBox.Show("Match added.", "Information", MessageBoxButtons.OK); Close(); return; } } MessageBox.Show("Match needs to be scheduled at least 3 days earlier.", "Information", MessageBoxButtons.OK); return; } catch (Exception) { MessageBox.Show("Error", "Something went wrong", MessageBoxButtons.OK); throw; } } }
public RefereeMatches AddRefereeMatch(RefereeMatches refereeMatch) { return(_serviceRefereeMatch.Insert(refereeMatch)); }