// GET: Patients/Edit/5 public async Task <IActionResult> Edit(Int32?id) { if (id == null) { return(this.NotFound()); } var patient = await this.context.Patients .SingleOrDefaultAsync(m => m.Id == id); if (patient == null) { return(this.NotFound()); } var model = new PatientCreateAndEditModel { Name = patient.Name, Address = patient.Address, BirthDay = patient.BirthDay, Gender = patient.Gender }; return(this.View(model)); }
public async Task <IActionResult> Edit(Int32?id, PatientCreateAndEditModel model) { if (id == null) { return(this.NotFound()); } var patient = await this.context.Patients .SingleOrDefaultAsync(m => m.Id == id); if (patient == null) { return(this.NotFound()); } if (this.ModelState.IsValid) { patient.Name = model.Name; patient.Address = model.Address; patient.BirthDay = model.BirthDay; patient.Gender = model.Gender; await this.context.SaveChangesAsync(); return(this.RedirectToAction("Index")); } return(this.View(model)); }
public async Task <IActionResult> Create(PatientCreateAndEditModel model) { if (this.ModelState.IsValid) { var patient = new Patient { Name = model.Name, Address = model.Address, BirthDay = model.BirthDay, Gender = model.Gender }; this.context.Patients.Add(patient); await this.context.SaveChangesAsync(); return(this.RedirectToAction("Index")); } return(this.View(model)); }