Exemplo n.º 1
0
        public ActionResult Create(AircraftEditViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                if (_dataService.GetAircraftByRegNumber(viewModel.RegistrationNumber) == null)
                {
                    Aircraft entity = new Aircraft();
                    entity = CopyDataFromViewModel(entity, viewModel);
                    _dataService.AddAircraft(entity);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("RegistrationNumber", "Aircraft with registration number already exists in the database");
                }
            }

            return(View(viewModel));
        }