Пример #1
0
        public IEnumerable <FeaturedVehicle> GetFeatured()
        {
            var makeRepo  = new VehicleMakeRepoQA();
            var makes     = makeRepo.GetVehicleMakes();
            var modelRepo = new VehicleModelRepoQA();
            var models    = modelRepo.GetVehicleModels();

            var featuredVehicles = (from vehicleListing in _vehicleListings
                                    join make in makes
                                    on vehicleListing.VehicleMakeId equals make.VehicleMakeId
                                    join model in models
                                    on vehicleListing.VehicleModelId equals model.VehicleModelId
                                    where vehicleListing.FeaturedVehicle == true
                                    select new FeaturedVehicle
            {
                VehicleListingId = vehicleListing.VehicleListingId,
                Year = vehicleListing.Year,
                VehicleMakeId = vehicleListing.VehicleMakeId,
                VehicleMakeName = make.VehicleMakeName,
                VehicleModelId = vehicleListing.VehicleModelId,
                VehicleModelName = model.VehicleModelName,
                SalePrice = vehicleListing.SalePrice,
                ImageFileName = vehicleListing.ImageFileName
            }).Take(8);

            return(featuredVehicles);
        }
Пример #2
0
        public IEnumerable <InventoryReportItem> GetInventoryReport(int vehicleTypeId)
        {
            var vehicleRepo = new VehicleListingRepoQA();
            var vehicles    = vehicleRepo.GetAll();
            var makesRepo   = new VehicleMakeRepoQA();
            var makes       = makesRepo.GetVehicleMakes();
            var modelsRepo  = new VehicleModelRepoQA();
            var models      = modelsRepo.GetVehicleModels();

            var reportItems = from v in vehicles
                              join make in makes on v.VehicleMakeId equals make.VehicleMakeId
                              join model in models on v.VehicleModelId equals model.VehicleModelId
                              where v.VehicleTypeId == vehicleTypeId
                              group v by new
            {
                make.VehicleMakeName,
                model.VehicleModelName,
                v.Year
            } into grp
                select new InventoryReportItem
            {
                Year             = grp.Key.Year,
                VehicleMakeName  = grp.Key.VehicleMakeName,
                VehicleModelName = grp.Key.VehicleModelName,
                Count            = grp.Count(),
                StockValue       = grp.Sum(v => v.MSRP)
            };

            return(reportItems);
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        public void Insert(ModelsItem model)
        {
            VehicleModel newModel = new VehicleModel()
            {
                VehicleMakeId    = model.VehicleMakeId,
                VehicleModelName = model.VehicleModelName,
                UserId           = model.UserId,
                CreatedDate      = DateTime.Now
            };

            var lastId   = _vehicleModels.MaxBy(x => x.VehicleModelId).FirstOrDefault();
            int newId    = lastId.VehicleModelId + 1;
            var makeRepo = new VehicleMakeRepoQA();

            model.VehicleMakeName = makeRepo.GetById(model.VehicleMakeId).VehicleMakeName;

            newModel.VehicleModelId = newId;
            model.VehicleModelId    = newId;
            model.CreatedDate       = DateTime.Now;

            _vehicleModels.Add(newModel);
            _modelsItems.Add(model);
        }
Пример #5
0
        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);
        }