Beispiel #1
0
        public static ICar AddCar(int tournamentID, ICar car)
        {
            IRlmRepository repo   = RepositoryManager.GetDefaultRepository();
            Car            newCar = Car.From(car);

            lock (_lock)
            {
                Tournament tournament = repo.LoadTournament(tournamentID);

                // find an ID to assign to this new Car
                int maxID = 0;
                foreach (Car c in tournament.CarData)
                {
                    if (c.ID > maxID)
                    {
                        maxID = c.ID;
                    }
                }

                newCar.ID = maxID + 1;
                tournament.CarData.Add(newCar);

                repo.SaveTournament(tournament);
            }

            CarsUpdated?.Invoke(tournamentID, new CarsUpdatedEventArgs(GetCars(tournamentID)));
            StandingsUpdated?.Invoke(tournamentID, new StandingsUpdatedEventArgs(GetStandings(tournamentID)));

            return(newCar);
        }
Beispiel #2
0
        public static ICar DeleteCar(int tournamentID, int carID)
        {
            IRlmRepository repo       = RepositoryManager.GetDefaultRepository();
            Car            deletedCar = null;

            lock (_lock)
            {
                Tournament tournament = repo.LoadTournament(tournamentID);

                deletedCar = tournament.CarData.Where(c => c.ID == carID).SingleOrDefault();
                tournament.CarData.Remove(deletedCar);

                repo.SaveTournament(tournament);
            }

            CarsUpdated?.Invoke(tournamentID, new CarsUpdatedEventArgs(GetCars(tournamentID)));
            StandingsUpdated?.Invoke(tournamentID, new StandingsUpdatedEventArgs(GetStandings(tournamentID)));

            return(deletedCar);
        }