public async Task <IActionResult> Create(CreateCarModel createCarModel, int id) { var generation = generationsService.GetById(id); var engine = enginesService.GetById(createCarModel.EngineId); if (generation == null) { return(this.BadRequest()); } var car = Mapper.Map <Car>(createCarModel); car.GenerationId = id; if (this.carsService.Exists(car)) { this.ModelState.AddModelError("", GlobalConstants.CAR_ALREADY_EXISTS); } ValidateTireInfo(createCarModel.TireInfo); if (!this.ModelState.IsValid) { SetUpViewBag(generation); return(this.View()); } await carsService.AddAsync(car); return(this.RedirectToAction(nameof(All), new { id })); }
public IActionResult Edit(int id) { var engine = enginesService.GetById(id); if (engine == null) { return(this.BadRequest()); } var viewModel = Mapper.Map <EditEngineModel>(engine); return(this.View(viewModel)); }