Пример #1
0
        public ActionResult Create(CarModelViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                // Checks if car model already exists:
                if (logic.IsCarModelExists(model.CarModel))
                {
                    ViewBag.ErrorMessage = "Car model already exists.";
                    return(View(model));
                }
                else
                {
                    // Car model is OK to insert:
                    logic.InsertCarModel(model.CarModel);
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception)
            {
                ViewBag.ErrorMessage = "An error has occurred. please try again later.";
                return(View(model));
            }
        }
Пример #2
0
        public ActionResult Edit(CarModelViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                logic.UpdateCarModel(model.CarModel);
                return(RedirectToAction("Index"));
            }
            catch (Exception)
            {
                ViewBag.ErrorMessage = "An error has occurred. please try again later.";
                return(View(model));
            }
        }
Пример #3
0
        /// <summary>
        /// Page displays: A form to edit a car model.
        /// </summary>
        public ActionResult Edit(int id = 0)
        {
            try
            {
                // Gets the car model by the ID:
                CarModel carModel = logic.GetCarModelByID(id);
                if (carModel == null)
                {
                    return(HttpNotFound());
                }

                // Creates the model object:
                CarModelViewModel model = new CarModelViewModel();
                model.CarModel = carModel;
                return(View(model));
            }
            catch (Exception)
            {
                ViewBag.ErrorMessage = "An error has occurred. please try again later.";
                return(View(new CarModelViewModel()));
            }
        }