public ActionResult Details(int id)
        {
            var vehicle = vRepo.GetById(id);

            vehicle.Make  = makeRepo.GetById(vehicle.MakeId);
            vehicle.Model = modelRepo.GetById(vehicle.ModelId);

            return(View(vehicle));
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            var model = vRepo.GetAll().Where(v => v.Type != "Sold");

            foreach (var vehicle in model)
            {
                vehicle.Make  = makeRepo.GetById(vehicle.MakeId);
                vehicle.Model = modelRepo.GetById(vehicle.ModelId);
            }
            return(View(model));
        }
        public IEnumerable <Vehicle> Search(string type, string term, decimal minPrice, decimal maxPrice, int minYear, int maxYear)
        {
            IModelRepo            modelRepo = Factory.GetModelRepo();
            IMakeRepo             makeRepo  = Factory.GetMakeRepo();
            IEnumerable <Vehicle> vehicles  = new List <Vehicle>();

            switch (type)
            {
            case "new":
                vehicles = GetAll().Where(v => v.Type == "New");
                break;

            case "used":
                vehicles = GetAll().Where(v => v.Type == "Used");
                break;

            case "all":
                vehicles = GetAll().Where(v => v.Type != "Sold");
                break;

            default:
                break;
            }
            List <Vehicle> found = new List <Vehicle>();

            //validated here so we don't pass in another parameter
            int year = 0;

            int.TryParse(term, out year);

            foreach (var vehicle in vehicles)
            {
                vehicle.Make  = makeRepo.GetById(vehicle.MakeId);
                vehicle.Model = modelRepo.GetById(vehicle.ModelId);

                if (vehicle.Year >= minYear && vehicle.Year <= maxYear && vehicle.SalePrice >= minPrice && vehicle.SalePrice <= maxPrice)
                {
                    if (term != "hamster")
                    {
                        if (vehicle.Year == year || vehicle.Make.MakeName.ToLower().Contains(term.ToLower()) || vehicle.Model.ModelName.ToLower().Contains(term.ToLower()))
                        {
                            found.Add(vehicle);
                        }
                    }
                    else
                    {
                        found.Add(vehicle);
                    }
                }
            }

            vehicles = found;
            return(vehicles);
        }
        public ActionResult Inventory()
        {
            IEnumerable <Vehicle> allVehicles = vRepo.GetAll();

            foreach (var item in allVehicles)
            {
                item.Make  = makeRepo.GetById(item.MakeId);
                item.Model = modelRepo.GetById(item.ModelId);
            }

            IEnumerable <Vehicle> newVehicles       = allVehicles.Where(v => v.Type == "New");
            IEnumerable <Vehicle> usedVehicles      = allVehicles.Where(v => v.Type == "Used");
            InventoryReportVM     inventoryReportVM = new InventoryReportVM();

            inventoryReportVM.UsedInventory = Inventory(usedVehicles);
            inventoryReportVM.NewInventory  = Inventory(newVehicles);
            return(View(inventoryReportVM));
        }
        public ActionResult Index()
        {
            var specials = specialRepo.GetAll();

            var vehicles = vRepo.GetAll().Where(v => v.IsFeatured == true).Where(w => w.Type != "Sold");

            foreach (var vehicle in vehicles)
            {
                vehicle.Make  = makeRepo.GetById(vehicle.MakeId);
                vehicle.Model = modelRepo.GetById(vehicle.ModelId);
            }

            var model = new HomeIndexVM()
            {
                Vehicles = vehicles,
                Specials = specials
            };

            return(View(model));
        }