Esempio n. 1
0
        public ProductsForTimeline Populate(GamesForRaceDay gamesForRaceDay)
        {
            ProductsForTimeline productsForTimeline = _mapper.Map <ProductsForTimeline>(gamesForRaceDay);

            List <ProductForTimeline> allProducts = new List <ProductForTimeline>();

            var activeMultiLegProductForTimelines = _mapper.Map <List <ActiveMultiLegProductForTimeline> >(gamesForRaceDay.MultiLegGames);

            foreach (var game in activeMultiLegProductForTimelines)
            {
                game.ProgressStatus    = GetGameStatus(game, gamesForRaceDay.Races);
                game.ConsecutiveLegs   = CalculateConsecutiveLegs(game).ToArray();
                game.EarliestRaceStart = (from race in gamesForRaceDay.Races
                                          where game.Races.Contains(race.RaceNumber)
                                          orderby race.StartTime
                                          select race.StartTime).First();
            }

            allProducts.AddRange(activeMultiLegProductForTimelines);

            List <ActiveSingleLegProductForTimeline> singleLegProducts = (from slg in gamesForRaceDay.SingleLegGames.DistinctBy(s => s.Product)
                                                                          let race = gamesForRaceDay.Races.Single(r => r.RaceNumber == slg.RaceNumber)
                                                                                     let legs = gamesForRaceDay.SingleLegGames.Where(s => s.Product == slg.Product)
                                                                                                select new ActiveSingleLegProductForTimeline()
            {
                Product = slg.Product,
                EarliestRaceStart = race.StartTime,
                Races = _mapper.Map <List <RaceForSingleLegGame> >(legs)
            }).ToList();

            allProducts.AddRange(singleLegProducts);
            allProducts.Sort();
            productsForTimeline.Products = allProducts;


            return(productsForTimeline);
        }
Esempio n. 2
0
        public IHttpActionResult GetProductsForTimeline(string raceDayKey)
        {
            GamesForRaceDay gamesForRaceDay = _raceDayServiceGateway.GetGamesForRaceDay(RaceDayKey.FromString(raceDayKey));

            return(Ok(RestResult <ProductsForTimeline> .CreateSuccess(_viewModelPopulator.Populate(gamesForRaceDay))));
        }