public ActionResult Create(FleetCarViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } // Checks if a car in the fleet already exists: if (logic.IsFleetCarExists(model.FleetCar.LicensePlate)) { ViewBag.ErrorMessage = "Car already exists in the fleet."; return(View(model)); } else { // Car in the fleet is OK to insert: logic.InsertFleetCar(model.FleetCar); return(RedirectToAction("Index")); } } catch (Exception) { ViewBag.ErrorMessage = "An error has occurred. please try again later."; return(View(model)); } }
public ActionResult Edit(FleetCarViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } logic.UpdateFleetCar(model.FleetCar); return(RedirectToAction("Index")); } catch (Exception) { ViewBag.ErrorMessage = "An error has occurred. please try again later."; return(View(model)); } }
/// <summary> /// Page displays: A form to edit a car in the fleet. /// </summary> public ActionResult Edit(string licensePlate) { try { FleetCar fleetCar = logic.GetFleetCarByLicensePlate(licensePlate); if (fleetCar == null) { return(HttpNotFound()); } FleetCarViewModel model = new FleetCarViewModel(); model.FleetCar = fleetCar; return(View(model)); } catch (Exception) { ViewBag.ErrorMessage = "An error has occurred. please try again later."; return(View(new FleetCarViewModel())); } }