void ReleaseDesignerOutlets() { if (AwayGoals != null) { AwayGoals.Dispose(); AwayGoals = null; } if (AwayName != null) { AwayName.Dispose(); AwayName = null; } if (HomeGoals != null) { HomeGoals.Dispose(); HomeGoals = null; } if (HomeName != null) { HomeName.Dispose(); HomeName = null; } }
public async void OnNavigatedTo(NavigationContext navigationContext) { var id = (int)navigationContext.Parameters["id"]; this.IsEditing = (bool)navigationContext.Parameters["isEditing"]; Match = await refereeService.GetMatchAsync(id); if (Match.HomeTeamScore == null && this.IsEditing) { Match.HomeTeamScore = 0; Match.AwayTeamScore = 0; } Teams.Add(new Tuple <int, string>(Match.HomeTeamId, Match.HomeTeamName)); Teams.Add(new Tuple <int, string>(Match.AwayTeamId, Match.AwayTeamName)); SelectedTeam = Teams.First(); HomeGoals.AddRange(Match.HomeTeamGoals.OrderBy(x => x.Time)); AwayGoals.AddRange(Match.AwayTeamGoals.OrderBy(x => x.Time)); SelectedPlayer = Players.First(); //if (Match.HomeTeamScore != null) //{ // IsEditing = false; //} // Center the map to stadium: var address = Match.Stadium.Address; this.To = $"{address.Street}, {address.Number}, {address.City}, {address.Zipcode}"; var p = geocodingService.GetLocationFromStringQuery(this.To); DirectionsMap.Center = p; DirectionsMap.ZoomLevel = 14; DirectionsMap.Children.Add(new Pushpin { Location = p }); IsEnabled = false; }
public EditMatchFormViewModel(IRegionManager regionManager, IRefereeService refereeService, IInteractionService interactionService, IGeocodingService geocodingService) { CalculateRouteCommand = new MyDelegateCommand(CalculateRoute); this.regionManager = regionManager; this.refereeService = refereeService; this.interactionService = interactionService; this.geocodingService = geocodingService; AddGoalCommand = new DelegateCommand(() => { var teamId = Match.HomeTeamPlayers.Contains(SelectedPlayer) ? (SelectedType == GoalType.Own ? Match.AwayTeamId : Match.HomeTeamId) : (SelectedType == GoalType.Own ? Match.HomeTeamId : Match.AwayTeamId); var goal = new GoalDTO() { Scorer = SelectedPlayer, GoalType = SelectedType, TeamId = teamId, Time = Time }; if (teamId == Match.HomeTeamId) { HomeGoals.Add(goal); var ordered = this.HomeGoals.OrderBy(x => x.Time).ToList(); this.HomeGoals.Clear(); this.HomeGoals.AddRange(ordered); Match.HomeTeamScore = (Match.HomeTeamScore ?? 0) + 1; } else { AwayGoals.Add(goal); var ordered = this.AwayGoals.OrderBy(x => x.Time).ToList(); this.AwayGoals.Clear(); this.AwayGoals.AddRange(ordered); Match.AwayTeamScore = (Match.AwayTeamScore ?? 0) + 1; } this.interactionService.ShowMessageBox("Success", "Goal was added successfully"); }); RemoveGoalCommand = new DelegateCommand <GoalDTO>((goal) => { if (HomeGoals.Contains(goal)) { HomeGoals.Remove(goal); Match.HomeTeamScore--; } else { AwayGoals.Remove(goal); Match.AwayTeamScore--; } }); OkCommand = new DelegateCommand(async() => { if (IsEditing) { IsEnabled = true; Match.HomeTeamGoals = HomeGoals.ToArray(); Match.AwayTeamGoals = AwayGoals.ToArray(); if (Match.HomeTeamScore == null) { Match.HomeTeamScore = 0; } if (Match.AwayTeamScore == null) { Match.AwayTeamScore = 0; } await this.refereeService.SaveGoalsAsync(Match); IsEnabled = false; } GlobalCommands.GoBackCommand.Execute(null); }); }