public IActionResult CreateCarType(CarsCreateCarModelVM carTypeModel) { bool status = carsService.CreateCarType(carTypeModel); CarsCreateUpdateVM model = carsService.PrepareDataForCreateCars(); return(RedirectToAction("Create")); }
public int createCar(CarsCreateUpdateVM model) { Car car = null; if (model.CarId != 0) { car = context.Car.Find(model.CarId); } else { car = new Car(); context.Car.Add(car); } car.CarModelId = model.CarModelId; car.ChassisNumber = model.ChassisNumber; car.EngineNumber = model.EngineNumber; car.EnginPowerKS = float.Parse(model.EnginPowerKS); car.EnginPowerKW = float.Parse(model.EnginPowerKW); car.Fuel = model.Fuel; car.ProductionYear = model.ProductionYear; context.SaveChanges(); return(car.CarId); }
public IActionResult Edit(int id) { CarsCreateUpdateVM model = carsService.getCarUpdateDetails(id); if (model == null) { Response.StatusCode = 404; return(View("CarNotFound", id)); } return(View(model)); }
public IActionResult Create(CarsCreateUpdateVM model) { if (ModelState.IsValid) { int carId = carsService.createCar(model); return(RedirectToAction("Index")); } model = carsService.PrepareDataForCreateCars(); return(View("Create", model)); }
public CarsCreateUpdateVM PrepareDataForCreateCars() { CarsCreateUpdateVM model = new CarsCreateUpdateVM { listCarModels = context.CarModel.Select(x => new SelectListItem { Value = x.CarModelId.ToString(), Text = x.CarBrand.Name + " " + x.Name }).ToList(), //listFuels = Enum.GetValues(typeof(Fuel)).Cast<Fuel>().Select(x => new SelectListItem //{ // Text = x.ToString(), // Value = ((int)x).ToString() //}).ToList() }; return(model); }
public CarsCreateUpdateVM getCarUpdateDetails(int id) { CarsCreateUpdateVM model = context.Car.Where(x => x.CarId == id) .Select(x => new CarsCreateUpdateVM { CarId = x.CarId, CarModelId = x.CarModelId, CarModel = x.CarModel.Name + " " + x.CarModel.CarBrand.Name, ChassisNumber = x.ChassisNumber, EngineNumber = x.EngineNumber, EnginPowerKS = x.EnginPowerKS.ToString(), EnginPowerKW = x.EnginPowerKW.ToString(), Fuel = x.Fuel, ProductionYear = x.ProductionYear, listCarModels = context.CarModel.Select(x => new SelectListItem { Value = x.CarModelId.ToString(), Text = x.CarBrand.Name + " " + x.Name }).ToList() }).SingleOrDefault(); return(model); }
public IActionResult Create() { CarsCreateUpdateVM model = carsService.PrepareDataForCreateCars(); return(View(model)); }