Esempio n. 1
0
        public IEnumerable <ShortCar> SearchUsed(ListingSearchPerameters perameters)
        {
            List <Cars> shortCars = Cars.Where(c => c.CarTypeId == 1).ToList();

            if (perameters.MaxYear != null)
            {
                shortCars = shortCars.Where(c => c.CarYear < perameters.MaxYear).ToList();
            }
            if (perameters.MinYear != null)
            {
                shortCars = shortCars.Where(c => c.CarYear > perameters.MinYear).ToList();
            }
            if (perameters.MinPrice != null)
            {
                shortCars = shortCars.Where(c => c.SalesPrice > perameters.MinPrice).ToList();
            }
            if (perameters.MaxPrice != null)
            {
                shortCars = shortCars.Where(c => c.SalesPrice < perameters.MaxPrice).ToList();
            }
            IMCarModelRepo carModelRepository = new IMCarModelRepo();
            int            modelID            = carModelRepository.GetAll().Where(c => perameters.MakeModel == c.CarModelName).FirstOrDefault().CarModelId;
            IMMakeRepo     carMakeRepo        = new IMMakeRepo();
            int            makeID             = carMakeRepo.GetAll().Where(c => perameters.MakeModel == c.MakeName).FirstOrDefault().MakeId;
            IMMakeRepo     makeRepo           = new IMMakeRepo();

            if (perameters.MakeModel != null)
            {
                shortCars = shortCars.Where(c => c.CarModelId == modelID || makeRepo.GetAll().Where(m => m.MakeId == makeID).FirstOrDefault().MakeName == perameters.MakeModel).ToList();
            }
            List <ShortCar> toReturn = new List <ShortCar>();

            foreach (var car in shortCars)
            {
                toReturn.Add(new ShortCar()
                {
                    CarId    = car.CarId,
                    CarModel = carModelRepository.GetAll().Where(c => c.CarModelId == car.CarModelId).FirstOrDefault().CarModelName,
                    CarMake  = carMakeRepo.Get(carModelRepository.GetAll().Where(c => c.CarModelId == car.CarModelId).FirstOrDefault().MakeId).MakeName,
                    Photo    = Cars.Where(c => c.CarId == car.CarId).FirstOrDefault().Photo,
                    Price    = Cars.Where(c => c.CarId == car.CarId).FirstOrDefault().SalesPrice,
                    Year     = Cars.Where(c => c.CarId == car.CarId).FirstOrDefault().CarYear,
                });
            }
            return(toReturn);
        }
Esempio n. 2
0
        public List <Cars> GetByMake(int id)
        {
            IMCarModelRepo carModelRepository = new IMCarModelRepo();

            return(Cars.Where(c => c.CarModelId == carModelRepository.GetAll().Where(n => n.MakeId == id).FirstOrDefault().MakeId).ToList());
        }