public ListingDetailItem GetDetails(int listingId)
        {
            var bodyStyleRepo        = new BodyStyleRepoQA();
            var colorRepo            = new ColorRepoQA();
            var transmissionTypeRepo = new TransmissionTypeRepoQA();
            var makeRepo             = new VehicleMakeRepoQA();
            var modelRepo            = new VehicleModelRepoQA();
            var typeRepo             = new VehicleTypeRepoQA();

            var listing = GetById(listingId);

            if (listing == null)
            {
                return(null);
            }
            else
            {
                ListingDetailItem details = new ListingDetailItem();

                details.VehicleListingId     = listing.VehicleListingId;
                details.Year                 = listing.Year;
                details.VehicleMakeId        = listing.VehicleMakeId;
                details.VehicleMakeName      = makeRepo.GetById(listing.VehicleMakeId).VehicleMakeName;
                details.VehicleModelId       = listing.VehicleModelId;
                details.VehicleModelName     = modelRepo.GetById(listing.VehicleModelId).VehicleModelName;
                details.BodyStyleId          = listing.BodyStyleId;
                details.BodyStyleName        = bodyStyleRepo.GetById(listing.BodyStyleId).BodyStyleName;
                details.TransmissionTypeId   = listing.TransmissionTypeId;
                details.TransmissionTypeName = transmissionTypeRepo.GetById(listing.TransmissionTypeId).TransmissionTypeName;
                details.SalePrice            = listing.SalePrice;
                details.Mileage              = listing.Mileage;
                details.MSRP                 = listing.MSRP;
                details.InteriorColorId      = listing.InteriorColorId;
                details.InteriorColor        = colorRepo.GetById(listing.InteriorColorId).ColorName;
                details.ColorId              = listing.ColorId;
                details.ColorName            = colorRepo.GetById(listing.ColorId).ColorName;
                details.VIN           = listing.VIN;
                details.ImageFileName = listing.ImageFileName;
                details.Description   = listing.Description;


                return(details);
            }
        }
        public IEnumerable <ListingSearchItem> GetSearchResults(ListingSearchParameters parameters)
        {
            var listings   = GetAll();
            var makesRepo  = new VehicleMakeRepoQA();
            var modelsRepo = new VehicleModelRepoQA();
            var bodyRepo   = new BodyStyleRepoQA();
            var transRepo  = new TransmissionTypeRepoQA();
            var colorRepo  = new ColorRepoQA();

            var makes  = makesRepo.GetVehicleMakes();
            var models = modelsRepo.GetVehicleModels();
            var styles = bodyRepo.GetAll();
            var trans  = transRepo.GetAll();
            var colors = colorRepo.GetAll();

            var query = from l in listings
                        join ma in makes on l.VehicleMakeId equals ma.VehicleMakeId
                        join mo in models on l.VehicleModelId equals mo.VehicleModelId
                        join s in styles on l.BodyStyleId equals s.BodyStyleId
                        join t in trans on l.TransmissionTypeId equals t.TransmissionTypeId
                        join c in colors on l.ColorId equals c.ColorId
                        join ic in colors on l.InteriorColorId equals ic.ColorId
                        where l.Sold == false
                        orderby l.MSRP descending
                        select new ListingSearchItem
            {
                VehicleListingId     = l.VehicleListingId,
                Year                 = l.Year,
                VehicleMakeId        = l.VehicleMakeId,
                VehicleMakeName      = ma.VehicleMakeName,
                VehicleModelId       = l.VehicleModelId,
                VehicleModelName     = mo.VehicleModelName,
                BodyStyleId          = l.BodyStyleId,
                BodyStyleName        = s.BodyStyleName,
                TransmissionTypeId   = l.TransmissionTypeId,
                TransmissionTypeName = t.TransmissionTypeName,
                SalePrice            = l.SalePrice,
                Mileage              = l.Mileage,
                MSRP                 = l.MSRP,
                InteriorColorId      = l.InteriorColorId,
                InteriorColor        = ic.ColorName,
                ColorId              = l.ColorId,
                Color                = c.ColorName,
                VIN           = l.VIN,
                ImageFileName = l.ImageFileName,
                VehicleTypeId = l.VehicleTypeId
            };

            if (parameters.MinMSRP.HasValue)
            {
                query = query.Where(q => q.MSRP >= parameters.MinMSRP);
            }
            if (parameters.MaxMSRP.HasValue)
            {
                query = query.Where(q => q.MSRP <= parameters.MaxMSRP);
            }
            if (parameters.MinYear.HasValue)
            {
                query = query.Where(q => q.Year >= parameters.MinYear);
            }
            if (parameters.MaxYear.HasValue)
            {
                query = query.Where(q => q.Year <= parameters.MaxYear);
            }
            if (parameters.VehicleTypeId.HasValue)
            {
                query = query.Where(q => q.VehicleTypeId == parameters.VehicleTypeId);
            }
            if (!string.IsNullOrEmpty(parameters.SearchTerm))
            {
                query = query.Where(q => q.VehicleMakeName.Contains(parameters.SearchTerm) || q.VehicleModelName.Contains(parameters.SearchTerm) || q.Year.ToString().Contains(parameters.SearchTerm));
            }


            return(query);
        }