public async Task <ActionResult <IEnumerable <Race> > > GetAllRaces([FromQuery] uint season, [FromQuery] int locationId) { if (season == 0 || locationId == 0) { return(BadRequest()); } var races = (await _raceService.GetRaces()).Where(r => r.Location.Id == locationId && r.Date > SeasonParser.GetSeasonsStart(season) && r.Date < SeasonParser.GetSeasonsEnd(season)); return(Ok(races)); }
public async Task <IEnumerable <Run> > GetRunsForSkierInSeasons(int skierId, uint season) { var skier = await DaoProvider.SkierDao.FindById(skierId).ConfigureAwait(false); if (skier == null) { return(null); } var runs = await DaoProvider.RunDao.GetAllRunsForSkier(skier).ConfigureAwait(false); var seasonsStart = SeasonParser.GetSeasonsStart(season); var seasonsEnd = SeasonParser.GetSeasonsEnd(season); return(runs.Where(run => run.Race.Date >= seasonsStart && run.Race.Date <= seasonsEnd)); }
public async Task <ActionResult <Season> > GetSeason(uint season) { var skiSeason = new Season { Year = Convert.ToDateTime($"01.01.{season}") }; var races = (await _raceService.GetRaces()).Where(r => r.Date > SeasonParser.GetSeasonsStart(season) && r.Date < SeasonParser.GetSeasonsEnd(season)); if (!races.Any()) { return(NoContent()); } List <SkiEvent> events = new List <SkiEvent>(); foreach (var grouping in races.GroupBy(r => r.Location.Id)) { var skiEvent = new SkiEvent(); skiEvent.Location = await _locationService.GetLocation(grouping.Key); skiEvent.StartDate = grouping.Min(r => r.Date); skiEvent.EndDate = grouping.Max(r => r.Date); skiEvent.RaceTypes = grouping.Select(r => r.RaceType).Distinct(); skiEvent.Genders = grouping.Select(r => r.Gender).Distinct(); events.Add(skiEvent); } skiSeason.Events = events; return(Ok(skiSeason)); }