public static IEnumerable <Garage> LoadRandomPaged(
            YoumotoDbContext context,
            GarageTypes garageType,
            Int32 skip,
            Int32 take)
        {
            var garages = context.Garages
                          .Where(runner => garageType == GarageTypes.Any || runner.GarageType == garageType)
                          .Where(runner => runner.GaragePictures.Any())
                          .ToList();

            List <Garage> result     = new List <Garage>();
            List <Int32>  taken      = new List <Int32>();
            Random        randomizer = new Random();

            for (Int32 index = 0; index < take; index++)
            {
                Int32 randomIndex = 0;
                do
                {
                    randomIndex = randomizer.Next(0, garages.Count);
                }while (taken.Contains(randomIndex));

                taken.Add(randomIndex);
                result.Add(garages[randomIndex]);
            }

            return(result);
        }
Exemplo n.º 2
0
        public IEnumerable <GarageViewModels.Preview> LoadGarages(GarageTypes garageType, Int32 skip = 0, Int32 take = 5)
        {
            YoumotoDbContext context = this.context ?? new YoumotoDbContext();

            return(GaragePersister
                   .LoadRandomPaged(context, garageType, skip, take)
                   .Select(runner => new GarageViewModels.Preview(runner)));
        }