public RaceViewModel(RaceTable races, string title = "Races") { Title = title; Data = races; Items = new ObservableCollection <Race>(); LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand()); _source = DataSource.RacesProvided; }
public static void OpenRaces(ContentPage page, RaceOrigin origin, RaceTable races, Constructor constructor, bool warning = true) { if (races != null && constructor != null) { string title = "Races"; var racetable = new RaceTable(); switch (origin) { case RaceOrigin.ConstructorFastestLaps: title = constructor.Name + " Fastest Laps"; racetable = races; break; case RaceOrigin.ConstructorPodiums: title = constructor.Name + " Podiums"; racetable.Races = races.RacesPodiums; break; case RaceOrigin.ConstructorWins: title = constructor.Name + " Wins"; racetable.Races = races.RacesWon; break; case RaceOrigin.ConstructorPoles: title = constructor.Name + " Pole Positions"; racetable.Races = races.RacesPolePosition; break; case RaceOrigin.ConstructorRaces: title = constructor.Name + " Races"; racetable.Races = races.Races; break; default: break; } page.Navigation.PushAsync(new RacePage(new RaceViewModel(racetable, title))); } else { ShowWarning(page, warning); } }
public bool InsertRace(string _name, string _author, List <Vector3> pos) { int id = -1; using (var db = raceDbFactory.Open()) { if (!db.Exists <RaceTable>(new { name = _name, author = _author })) { RaceTable newRecord = new RaceTable { name = _name, author = _author }; db.Save(newRecord, true); id = newRecord.id; } } if (id != -1) { using (var db = cpDbFactory.Open()) { for (int i = 0; i < pos.Count; i++) { CheckpointTable newCp = new CheckpointTable { race_id = id, cp_idx = i, pos_x = pos[i].X, pos_y = pos[i].Y, pos_z = pos[i].Z }; db.Save(newCp); } } return(true); } return(false); }
async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; try { Constructor = null; switch (_source) { case DataSource.Id: dataoriginal = await App.RestService.GetConstructorAsync(ConstructorId); Title = dataoriginal.Name; break; case DataSource.Provided: default: break; } Constructor = dataoriginal; FastestLaps = await App.RestService.FastestLapsByConstructorAsync(ConstructorId); SeasonsWorldChampions = await App.RestService.GetSeasonsConstructorsWorldChampionAsync(ConstructorId); Races = await App.RestService.GetRacesByConstructorAsync(ConstructorId); Drivers = await App.RestService.DriversByConstructorAsync(ConstructorId); } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; try { switch (_source) { case DataSource.Seasons: Data = await App.RestService.GetRacesBySeasonAsync(Season.Year); break; case DataSource.RacesProvided: // If it's already provided, there's no need to request the data. break; case DataSource.All: default: Data = await App.RestService.GetRacesAsync(); break; } LoadItemsFromData(); } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public static void OpenRaces(ContentPage page, RaceOrigin origin, RaceTable races, Circuit circuit, bool warning = true) { if (races != null && circuit != null) { string title = "Races"; switch (origin) { case RaceOrigin.CircuitRaces: title = circuit.Name + " Races"; break; default: break; } page.Navigation.PushAsync(new RacePage(new RaceViewModel(races, title))); } else { ShowWarning(page, warning); } }