public ActionResult AddVehicle(long id, AddVehicleViewModel model) { ViewBag.ErrorFlag = false; ViewBag.DriverId = id; if (!ModelState.IsValid) { return(View()); } try { Driver driver = new Driver(id); driver.AddOrChangeVehicle(new Vehicle.RegisterationNumberFormat(model.Alphabets, model.Number, (short)model.Year.Year), model.CarModel, (int)model.EngineCC, model.IsAc, model.Color, new VehicleType(model.VehicleType)); return(RedirectToAction("ViewDetails", new { id = id })); } catch (UniqueKeyViolationException ex) { ViewBag.ErrorFlag = true; ModelState.AddModelError(String.Empty, ex.Message); return(View()); } catch (Exception ex) { return(RedirectToAction("ErrorPage", "Error", ex)); } }