コード例 #1
0
        public async Task <IActionResult> ListByCompetition(int id, string s, int?award = null)
        {
            List <Models.Crew> crews;

            Models.Competition comp = await _context.Competitions.Include(c => c.TimingPoints).FirstOrDefaultAsync(c => c.CompetitionId == id);

            if (comp is null)
            {
                return(NotFound());
            }

            if (award == null)
            {
                crews = await _context.Crews.Include(c => c.Results).Where(c => c.CompetitionId == id).ToListAsync();
            }
            else
            {
                Models.Award dbAward = await _context.Awards.Include("Crews.Crew.Results")
                                       .FirstOrDefaultAsync(a => a.AwardId == award);

                crews = dbAward.Crews.Select(x => x.Crew).ToList();
            }

            List <Crew> results = ResultsHelper.BuildCrewsList(_mapper, comp, crews);

            if (String.IsNullOrEmpty(s))
            {
                return(Ok(results));
            }
            else
            {
                return(Ok(results.Where(x => x.Name.ToUpper(CultureInfo.CurrentCulture)
                                        .Contains(s.ToUpper(CultureInfo.CurrentCulture), StringComparison.CurrentCulture)).ToList()));
            }
        }
コード例 #2
0
        public void BuildResultsList_WithFirstCrewTimeOnlyAndSecondCrewAtBarnes_ShouldReturnFirstCrewSecond()
        {
            List <Crew> crews = new List <Crew>();
            Crew        crew1 = new Crew {
                BroeCrewId = 1, Competition = Competition
            };

            crew1.BroeCrewId  = 1;
            crew1.Competition = Competition;
            crew1.Results.Add(new Result(StartPoint, crew1, new TimeSpan(2, 0, 0)));
            crew1.Results.Add(new Result(BarnesPoint, crew1, new TimeSpan(2, 4, 0)));
            crews.Add(crew1);

            Crew crew2 = new Crew {
                BroeCrewId = 2, Competition = Competition, IsTimeOnly = true
            };

            crew2.Results.Add(new Result(StartPoint, crew2, new TimeSpan(2, 1, 0)));
            crew2.Results.Add(new Result(FinishPoint, crew2, new TimeSpan(2, 20, 0)));
            crews.Add(crew2);

            List <HeadRaceTimingSite.Api.Resources.Crew> results = ResultsHelper.BuildCrewsList(mapper, Competition, crews);

            Assert.AreEqual(1, results[0].Id);
            Assert.AreEqual(2, results[1].Id);
        }
コード例 #3
0
        public async Task <IActionResult> DetailsAsCsv(int?id)
        {
            Competition competition = await _context.Competitions.Include(c => c.TimingPoints).FirstOrDefaultAsync(c => c.CompetitionId == id);

            IEnumerable <Crew> crews = await _context.Crews.Where(c => c.CompetitionId == id).Include(x => x.Results)
                                       .Include("Athletes.Athlete").Include(x => x.Penalties).ToListAsync();

            return(Ok(_mapper.Map <IList <CsvCrewViewModel> >(ResultsHelper.BuildCrewsList(_mapper, competition, crews))));
        }
コード例 #4
0
        public void BuildResultsList_WithNoCrewsWithTimesButTimeOnlyFirst_ShouldReturnStartOrder()
        {
            List <Crew> crews = new List <Crew>();
            Crew        crew1 = new Crew {
                BroeCrewId = 1, IsTimeOnly = true, Competition = Competition
            };

            crews.Add(crew1);

            Crew crew2 = new Crew {
                BroeCrewId = 2, Competition = Competition
            };

            crews.Add(crew2);

            List <HeadRaceTimingSite.Api.Resources.Crew> results = ResultsHelper.BuildCrewsList(mapper, Competition, crews);

            Assert.AreEqual(1, results[0].Id);
            Assert.AreEqual(2, results[1].Id);
        }
コード例 #5
0
        public void BuildResultsList_WithSingleCrewWithTime_ShouldRankItFirst()
        {
            List <Crew> crews = new List <Crew>();
            Crew        crew1 = new Crew {
                BroeCrewId = 1, Competition = Competition
            };

            crews.Add(crew1);

            Crew crew2 = new Crew {
                BroeCrewId = 2, Competition = Competition
            };

            crew2.Results.Add(new Result(StartPoint, crew2, new TimeSpan(2, 0, 0)));
            crew2.Results.Add(new Result(FinishPoint, crew2, new TimeSpan(2, 20, 0)));
            crews.Add(crew2);

            List <HeadRaceTimingSite.Api.Resources.Crew> results = ResultsHelper.BuildCrewsList(mapper, Competition, crews);

            Assert.AreEqual(2, results[0].Id);
            Assert.AreEqual(1, results[1].Id);
        }