public async Task <IActionResult> Edit(Int32?id, DoctorCreateEditViewModel model) { if (id == null) { return(NotFound()); } var doctor = await this._context.Doctors. SingleOrDefaultAsync(m => m.Id == id); if (doctor == null) { return(this.NotFound()); } if (ModelState.IsValid) { doctor.Name = model.Name; doctor.Specialty = model.Specialty; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(doctor)); }
public async Task <IActionResult> Create(DoctorCreateEditViewModel model) { if (ModelState.IsValid) { var doctor = new Doctor { Name = model.Name, Specialty = model.Specialty }; _context.Add(doctor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
// GET: Doctors/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var doctor = await _context.Doctors.SingleOrDefaultAsync(m => m.Id == id); if (doctor == null) { return(NotFound()); } var model = new DoctorCreateEditViewModel { Name = doctor.Name, Specialty = doctor.Specialty }; return(View(model)); }