internal bool AddNewCar(CarsAddVM viewModel) { Cars car = new Cars(); if (!carRepository.CheckIfRegistrationNumberAlreadyExists(viewModel.Registrationnumber)) { car.CarType = viewModel.CarType; car.Kilometer = viewModel.Kilometer; car.AvailableForRent = true; car.Registrationnumber = viewModel.Registrationnumber; if (carRepository.Add(car).Id > 0) { eventsService.CreateAddedCarEvent(car); return(true); } else { return(false); } } else { return(false); } }
public IActionResult Add(CarsAddVM viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } if (!service.AddNewCar(viewModel)) { return(View(viewModel)); } return(RedirectToAction("ListOfAll", "Cars")); }