Пример #1
0
        public void ViewUpcomingRaces(IMainController _mainController, IShowUpcomingRacesView inForm)
        {
            RaceRepository _raceRepository = RaceRepository.GetInstance();

            List <Race> upRaces = _raceRepository.GetAllUnfinishedRaces();

            inForm.ShowModaless(_mainController, upRaces);
        }
        public void UpdateView()
        {
            _upRaces = _raceRepository.GetAllUnfinishedRaces().OrderBy(x => x.Date).ToList();

            UpdateList();
        }
Пример #3
0
        public void EnterRaceResults(IEnterResultsView inForm)
        {
            RaceRepository   raceRepository   = RaceRepository.GetInstance();
            DriverRepository driverRepository = DriverRepository.GetInstance();


            if (inForm.ShowViewModal(raceRepository.GetAllUnfinishedRaces(), driverRepository.GetAllActiveDrivers()) == true)
            {
                try
                {
                    string RaceName = inForm.RaceName;
                    if (string.IsNullOrEmpty(RaceName))
                    {
                        throw new ArgumentException("Race name is not selected!");
                    }

                    Race inRace = raceRepository.GetRaceByName(RaceName);

                    string result = inForm.Result;
                    if (string.IsNullOrEmpty(result))
                    {
                        throw new ArgumentException("Race standings is empty! Fill the textbox!");
                    }

                    List <int> driversResultsInt = this.ParseRaceStandings(result, driverRepository);

                    int fastestLap = -1;
                    if (Int32.TryParse(inForm.FastestLap, out fastestLap) == false)
                    {
                        throw new ArgumentException("The fastest lap result is not entered correctly!");
                    }
                    if (!driversResultsInt.Contains(fastestLap))
                    {
                        throw new ArgumentException("The fastest lap driver was not in the race!");
                    }


                    List <Driver> driversResults = new List <Driver>();
                    List <int>    points         = raceRepository.GetPoints();

                    for (int i = 0; i < driversResultsInt.Count(); ++i)
                    {
                        int    id    = driversResultsInt[i];
                        int    point = points[i];
                        Driver dr    = driverRepository.AddPoints(id, point);
                        driversResults.Add(dr);
                    }

                    Driver inFastestLap = driverRepository.AddPoints(fastestLap, 1);

                    RaceResults results = RaceFactory.CreateResults(driversResults, inFastestLap);

                    raceRepository.EnterResults(inRace.Name, results);
                }
                catch (RaceNotFoundException)
                {
                    MessageBox.Show("Picked race doesn't exist!");
                }
                catch (ArgumentException ex)
                {
                    MessageBox.Show(ex.Message + " Try again.");
                }
                catch (DriverNotFoundException)
                {
                    MessageBox.Show("Driver doesn't exist!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error:" + ex);
                }
            }
        }