public ActionResult Add(CreateCarBm bm) { if (!this.ModelState.IsValid) { // return model with this data } var appUserId = this.User.Identity.GetUserId(); bool isCreated = this.carManager.CreateCar(bm, appUserId); if (!isCreated) { // error page } return(this.RedirectToAction("UserProfile", "User")); }
public bool CreateCar(CreateCarBm bm, string appUserId) { int enginePower = this.EnginePowerToHp(bm.EnginePowerHp, bm.EnginePowerKw); if (enginePower == 0) { return(false); } int runningDistance = this.RunningDistanceToKm(bm.RunningDistanceKm, bm.RunningDistanceM); if (runningDistance == 0) { return(false); } Engine engine = new Engine() { FuelType = bm.FuelType, EngineSize = bm.EngineSize, EnginePower = enginePower }; Gearbox gearbox = new Gearbox() { GearBoxType = bm.GearBoxType, NumberOfGears = bm.NumberOfGears }; Car car = new Car() { Make = bm.Make, Model = bm.Model, FirstRegistration = bm.FirstRegistration, VIN = bm.VIN, RunningDistance = runningDistance, Engine = engine, Gearbox = gearbox }; bool isAdded = this.carService.AddCar(car, appUserId); return(true); }