public async Task <IActionResult> Create([Bind("Name,SerialNumber,Model")] CreateAirplaneViewModel airplane) { if (ModelState.IsValid) { var newAirplane = Airplane.Create(Guid.NewGuid(), airplane.Name, airplane.SerialNumber, airplane.Model, User.Identity.Name); _airplaneRepository.Add(newAirplane); return(RedirectToAction(nameof(Index))); } return(View(airplane)); }
public async Task <IActionResult> Create(CreateAirplaneViewModel inputModel) { var airplane = new Airplane { Model = inputModel.Model, Capacity = inputModel.Capacity }; await this.airplanes.Save(airplane); return(Ok()); }
// GET: Airplanes/Edit/5 public IActionResult Edit(Guid id) { try { var airplane = _airplaneRepository.GetById(id); var returnAirplane = new CreateAirplaneViewModel(airplane.Id, airplane.Name, airplane.SerialNumber, airplane.Model, airplane.CreatedBy, airplane.CreatedDate); return(View(returnAirplane)); } catch { return(NotFound()); } }
//[ValidateAntiForgeryToken] public async Task <IActionResult> Edit(Guid id, [Bind("Id,Name,SerialNumber,Model")] CreateAirplaneViewModel airplane) { try { var selectedAirplane = _airplaneRepository.GetById(id); if (ModelState.IsValid) { selectedAirplane.Update(airplane.Name, airplane.SerialNumber, airplane.Model); return(RedirectToAction(nameof(Index))); } return(View(airplane)); } catch (Exception ex) { return(NotFound()); } }