コード例 #1
0
        public ActionResult DeleteVehicle(int id)
        {
            CarMockRepository carRepo = new CarMockRepository();

            carRepo.Delete(id);
            return(RedirectToAction("Vehicles"));
        }
コード例 #2
0
        public ActionResult purchase(PurchaseCarViewModel vm)
        {
            CarMockRepository carRepo   = new CarMockRepository();
            MakeMockRepo      makeRepo  = new MakeMockRepo();
            ModelMockRepo     modelRepo = new ModelMockRepo();
            SaleMockRepo      saleRepo  = new SaleMockRepo();

            vm.Car = carRepo.GetById(vm.Car.CarId);

            //if (ModelState.IsValid)
            //{
            carRepo.ChangeToSold(vm.Car.CarId);

            var authManager = HttpContext.GetOwinContext().Authentication;

            vm.Sale.UserId = authManager.User.Identity.GetUserId();
            vm.Sale.CarId  = vm.Car.CarId;

            saleRepo.Create(vm.Sale);
            return(RedirectToAction("Index"));
            //}

            //vm.Car = carRepo.GetById(vm.Car.CarId);
            //vm.Car.Make = makeRepo.GetById(vm.Car.MakeId);
            //vm.Car.Model = modelRepo.GetById(vm.Car.ModelId);

            //return View(vm);
        }
コード例 #3
0
        protected static ICarService GetCarService()
        {
            var carRepository         = new CarMockRepository().Items;
            var carCategoryRepository = new CarCategoryMockRepository().Items;
            var garageRepository      = new GarageMockRepository().Items;

            return(new CarService(carRepository, carCategoryRepository, garageRepository));
        }
コード例 #4
0
        public ActionResult salesReport()
        {
            SaleReportViewModel SaleViewModel = new SaleReportViewModel();
            CarMockRepository   carMock       = new CarMockRepository();

            IEnumerable <Car> allCars      = carMock.GetAllCars();
            IEnumerable <Car> soldVehicles = allCars.Where(v => v.isSold == true);

            return(View(SaleViewModel));
        }
コード例 #5
0
        public ActionResult purchase(int id)
        {
            CarMockRepository    carRepo   = new CarMockRepository();
            MakeMockRepo         makeRepo  = new MakeMockRepo();
            ModelMockRepo        modelRepo = new ModelMockRepo();
            PurchaseCarViewModel vm        = new PurchaseCarViewModel();

            vm.Car       = carRepo.GetById(id);
            vm.Car.Make  = makeRepo.GetById(vm.Car.MakeId);
            vm.Car.Model = modelRepo.GetById(vm.Car.ModelId);
            return(View(vm));
        }
コード例 #6
0
        public IHttpActionResult Search(string searchType, string User, int minYear, int maxYear)
        {
            CarMockRepository repo  = new CarMockRepository();
            IEnumerable <Car> found = repo.Search(searchType, User, minYear, maxYear);

            if (found == null)
            {
                return(NotFound());
            }

            return(Ok(found));
        }
コード例 #7
0
        public IHttpActionResult Search(string type, string term, decimal minPrice, decimal maxPrice, int minYear, int maxYear)
        {
            CarMockRepository repo  = new CarMockRepository();
            IEnumerable <Car> found = repo.Search(type, term, minPrice, maxPrice, minYear, maxYear);

            if (found == null)
            {
                return(NotFound());
            }

            return(Ok(found));
        }
コード例 #8
0
        public ActionResult editVehicle(int id)
        {
            ModelMockRepo     modelRepo = new ModelMockRepo();
            MakeMockRepo      makeRepo  = new MakeMockRepo();
            CarMockRepository carRepo   = new CarMockRepository();
            CarEditViewModel  vm        = new CarEditViewModel();

            vm.Car       = carRepo.GetById(id);
            vm.Car.Make  = makeRepo.GetById(vm.Car.MakeId);
            vm.Car.Model = modelRepo.GetById(vm.Car.ModelId);
            vm.Makes     = new SelectList(makeRepo.GetAllMakes(), "MakeId", "MakeName");
            vm.Models    = new SelectList(modelRepo.GetAllModels(), "ModelId", "ModelName");
            return(View(vm));
        }
コード例 #9
0
        public ActionResult addVehicle(CarAddViewModel vm)
        {
            if (ModelState.IsValid)
            {
                CarMockRepository carRepo = new CarMockRepository();
                vm.Car.ImageFileName = vm.ImageUpload.FileName;
                Car car = carRepo.Create(vm.Car);
                vm.Car.CarId = car.CarId;
                return(RedirectToAction("editVehicle/" + vm.Car.CarId));
            }
            ModelMockRepo modelRepo = new ModelMockRepo();
            MakeMockRepo  makeRepo  = new MakeMockRepo();

            vm.Makes  = new SelectList(makeRepo.GetAllMakes(), "MakeId", "MakeName");
            vm.Models = new SelectList(modelRepo.GetAllModels(), "ModelId", "ModelName");
            return(View(vm));
        }
コード例 #10
0
        public ActionResult Index()
        {
            SpecialMockRepo       specialRepo = new SpecialMockRepo();
            FeaturedCarsViewModel vm          = new FeaturedCarsViewModel();
            CarMockRepository     carRepo     = new CarMockRepository();

            vm.Specials     = specialRepo.GetAllSpecials();
            vm.FeaturedCars = carRepo.GetAllCars().Where(m => m.isFeatured == true);
            MakeMockRepo  makeRepo  = new MakeMockRepo();
            ModelMockRepo modelRepo = new ModelMockRepo();

            foreach (var car in vm.FeaturedCars)
            {
                car.Make  = makeRepo.GetById(car.MakeId);
                car.Model = modelRepo.GetById(car.ModelId);
            }
            return(View(vm));
        }
コード例 #11
0
        public ActionResult editVehicle(CarEditViewModel vm)
        {
            if (ModelState.IsValid)
            {
                CarMockRepository carRepo = new CarMockRepository();
                if (vm.ImageUpload != null)
                {
                    vm.Car.ImageFileName = vm.ImageUpload.FileName;
                }
                vm.Car = carRepo.Update(vm.Car);
                return(RedirectToAction("Vehicles"));
            }
            ModelMockRepo modelRepo = new ModelMockRepo();
            MakeMockRepo  makeRepo  = new MakeMockRepo();

            vm.Makes  = new SelectList(makeRepo.GetAllMakes(), "MakeId", "MakeName");
            vm.Models = new SelectList(modelRepo.GetAllModels(), "ModelId", "ModelName");
            return(View(vm));
        }
コード例 #12
0
        public ActionResult Inventory()
        {
            CarInventoryViewModel inventoryViewModel = new CarInventoryViewModel();
            CarMockRepository     carMock            = new CarMockRepository();
            MakeMockRepo          makeRepo           = new MakeMockRepo();
            ModelMockRepo         modelRepo          = new ModelMockRepo();

            IEnumerable <Car> allCars = carMock.GetAllCars();

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

            IEnumerable <Car> newVehicles  = allCars.Where(v => v.Type == "New");
            IEnumerable <Car> usedVehicles = allCars.Where(v => v.Type == "Used");

            inventoryViewModel.UsedInventory = Inventory(usedVehicles);
            inventoryViewModel.NewInventory  = Inventory(newVehicles);
            return(View(inventoryViewModel));
        }