Exemple #1
0
        public async Task <bool> DeleteStartListMember(int raceId, int skierId, int runNo)
        {
            return(await Task.Run(() =>
            {
                var startlistAdo = new AdoStartListDao(connectionFactory);
                var raceDataAdo = new AdoRaceDataDao(connectionFactory);
                var racedata = raceDataAdo.FindAllBySkierId(skierId).FirstOrDefault(rd => rd.RaceId == raceId);
                if (!raceDataAdo.Delete(racedata))
                {
                    return false;
                }
                var race = new Race
                {
                    Id = raceId
                };
                var startList = new StartListMember
                {
                    Race = race,
                    SkierId = skierId,
                    RunNo = runNo
                };

                return startlistAdo.Delete(startList);
            }));
        }
Exemple #2
0
        public async Task <ICollection <SplitTimeModel> > GetSplittimesForSkier(int skierId, int runNo)
        {
            return(await Task.Run(() =>
            {
                var raceDatas = new AdoRaceDataDao(connectionFactory).FindAllBySkierId(skierId);
                raceDataForThisRaceRun = raceDatas.FirstOrDefault(data => data.RaceId == RaceControlModel.StartListModel.raceId);

                ActualSplitimes = new ObservableCollection <SplitTimeModel>();

                if (raceDataForThisRaceRun != null)
                {
                    var splittimes = new AdoSplitTimeDao(connectionFactory).FindByRaceDataId(raceDataForThisRaceRun.Id).Where(splittime => splittime.RunNo == runNo);

                    EvaluateWinnerSplittimes();

                    foreach (var splittime in splittimes)
                    {
                        ActualSplitimes.Add(new SplitTimeModel
                        {
                            RaceDataId = splittime.RaceDataId,
                            RunNo = splittime.RunNo,
                            SplitTimeNo = splittime.SplittimeNo,
                            Time = splittime.Time,
                            TimeOffsetToWinner = GetTimeOffsetToWinner(splittime.Time, splittime.SplittimeNo)
                        });
                    }
                }

                return ActualSplitimes;
            }));
        }
Exemple #3
0
        public SplitTimesController(ILogger <StartListController> logger)
        {
            _logger = logger;
            var connectionFactory = ConnectionFactoryHolder.getInstace().getConnectionFactory();

            _adoSplitTimeDao = new AdoSplitTimeDao(connectionFactory);
            _adoRaceDataDao  = new AdoRaceDataDao(connectionFactory);
        }
Exemple #4
0
 public void Import()
 {
     if (!AdoRaceDataDao.FindAll().Any())
     {
         RaceDatas = GenerateRaceDatas();
         foreach (var raceData in RaceDatas)
         {
             AdoRaceDataDao.Insert(raceData);
         }
     }
 }
Exemple #5
0
        public async Task <StartListModel> GetStartListForRaceId(int raceId, int runNo)
        {
            return(await Task.Run(() => {
                StartList = new StartListModel();
                StartList.raceId = raceId;
                StartList.StartListMembers = new ObservableCollection <StartListMemberModel>();

                IEnumerable <Skier> skiers = new AdoSkierDao(connectionFactory).FindAll();
                IEnumerable <RaceData> racedata = new AdoRaceDataDao(connectionFactory).FindAllByRaceId(raceId);

                if (skiers == null)
                {
                    throw new NullReferenceException("No skiers found");
                }

                IEnumerable <StartListMember> startListMembers =
                    new AdoStartListDao(connectionFactory)
                    .FindAllByRaceIdAndRunNo(raceId, runNo)
                    .OrderBy(startListMember => startListMember.StartPos);


                foreach (var startListMember in startListMembers)
                {
                    var skierdata = racedata.FirstOrDefault(data => data.SkierId == startListMember.SkierId);

                    StartList.StartListMembers.Add(
                        new StartListMemberModel()
                    {
                        Skier = new SkierModel(skiers.FirstOrDefault(skier => skier.Id == startListMember.SkierId)),
                        Startposition = startListMember.StartPos,
                        RunNo = startListMember.RunNo,
                        Blocked = skierdata != null && skierdata.Blocked,
                        Disqualified = skierdata != null && skierdata.Disqualified,
                        Finished = skierdata != null && skierdata.Finished,
                        Running = skierdata != null && skierdata.Running,
                        RaceDataId = skierdata?.Id ?? 0
                    }
                        );
                }

                return StartList;
            }));
        }
Exemple #6
0
        public async Task <bool> InsertStartListMember(int raceId, int skierId, int runNo, int startPosition)
        {
            return(await Task.Run(() =>
            {
                var startListAdo = new AdoStartListDao(connectionFactory);
                var raceDataAdo = new AdoRaceDataDao(connectionFactory);
                var oldRaceData = raceDataAdo.FindAllBySkierId(skierId).FirstOrDefault(rd => rd.RaceId == raceId);
                if (oldRaceData != null)
                {
                    raceDataAdo.Delete(oldRaceData);
                }
                var newRaceData = new RaceData()
                {
                    RaceId = raceId,
                    SkierId = skierId,
                    Blocked = true,
                    Disqualified = false,
                    Finished = false,
                    Running = false
                };
                if (raceDataAdo.Insert(newRaceData) == 0)
                {
                    return false;
                }

                var race = new Race
                {
                    Id = raceId
                };
                var startListMember = new StartListMember
                {
                    Race = race,
                    SkierId = skierId,
                    RunNo = runNo,
                    StartPos = startPosition
                };
                return startListAdo.Insert(startListMember) != 0;
            }));
        }
Exemple #7
0
 public RaceDataImporter(IConnectionFactory connectionFactory)
 {
     AdoRaceDataDao  = new AdoRaceDataDao(connectionFactory);
     AdoStartListDao = new AdoStartListDao(connectionFactory);
 }
 public void Setup()
 {
     configuration     = ConfigurationUtil.GetConfiguration();
     connectionFactory = DefaultConnectionFactory.FromConfiguration(configuration, "HuraceDbConnection");
     raceDataDao       = new AdoRaceDataDao(connectionFactory);
 }