Example #1
0
        public async Task AssignRunners()
        {
            var runnerEntities = _runnerRepository.GetAll();
            var runners        = _mapper.Map <IEnumerable <Runner> >(runnerEntities);

            var corralEntities = await _corralRepository.GetCorrals();

            var corrals        = _mapper.Map <IEnumerable <Corral> >(corralEntities);
            var criteriaCorral = new Dictionary <Corral, Func <Runner, bool> >();

            foreach (var corral in corrals)
            {
                Func <Runner, bool> criteria;
                if (corral.Name != "D")
                {
                    switch (corral.CriteriaType)
                    {
                    case CriteriaType.RaceTime:
                        criteria = _criteriaFactory.GenerateNumericCriteria(corral.MinRaceTime.Value, corral.MaxRaceTime.Value);
                        break;

                    case CriteriaType.Age:
                        criteria = _criteriaFactory.GenerateNumericCriteria(corral.MinAge.Value, corral.MaxAge.Value);
                        break;

                    case CriteriaType.Gender:
                        criteria = _criteriaFactory.GenerateGenderCriteria(corral.Gender);
                        break;

                    default:
                        criteria = runner => true;
                        break;
                    }
                }
                else
                {
                    criteria = runner => true;
                }
                criteriaCorral.Add(corral, criteria);
            }

            foreach (var runner in runners)
            {
                foreach (var corral in criteriaCorral.Keys)
                {
                    if (criteriaCorral[corral](runner) && corral.RunnerCount < corral.MaxElements)
                    {
                        runner.CorralId   = corral.Id;
                        runner.BIBNumber  = corral.StartBIBNumber + corral.RunnerCount;
                        runner.CorralName = corral.Name;
                        corral.RunnerCount++;
                        break;
                    }
                }
            }
            runnerEntities = _mapper.Map <IEnumerable <RunnerEntity> >(runners);
            await _runnerRepository.UpdateAllRunners(runnerEntities);
        }
Example #2
0
        public IEnumerable <Runner> GetAll()
        {
            var entities = _repository.GetAll();

            return(_mapper.Map <IEnumerable <Runner> >(entities));
        }