public async Task <IActionResult> Edit(Int32?diagnosisId, Int32?patientId, DiagnosisCreateAndEditModel model) { if (diagnosisId == null || patientId == null) { return(NotFound()); } var diagnosis = await context.Diagnoses .Include(w => w.Patient) .SingleOrDefaultAsync(m => m.DiagnosisId == diagnosisId && m.PatientId == patientId); if (diagnosis == null) { return(this.NotFound()); } this.ViewBag.Diagnosis = diagnosis; if (this.ModelState.IsValid) { diagnosis.Type = model.Type; diagnosis.Complications = model.Complications; diagnosis.Details = model.Details; await this.context.SaveChangesAsync(); return(this.RedirectToAction("Index", new { patientId = diagnosis.PatientId })); } return(this.View(model)); }
// GET: Diagnoses/Edit/5 public async Task <IActionResult> Edit(Int32?diagnosisId, Int32?patientId) { if (diagnosisId == null || patientId == null) { return(NotFound()); } var diagnosis = await context.Diagnoses .Include(w => w.Patient) .SingleOrDefaultAsync(m => m.DiagnosisId == diagnosisId && m.PatientId == patientId); if (diagnosis == null) { return(this.NotFound()); } this.ViewBag.Diagnosis = diagnosis; var model = new DiagnosisCreateAndEditModel { Type = diagnosis.Type, Complications = diagnosis.Complications, Details = diagnosis.Details }; return(this.View(model)); }
public async Task <IActionResult> Create(Int32?patientId, DiagnosisCreateAndEditModel model) { if (patientId == null) { return(this.NotFound()); } var patient = await this.context.Patients .SingleOrDefaultAsync(x => x.Id == patientId); if (patient == null) { return(this.NotFound()); } var diagnoses = await context.Diagnoses.ToListAsync(); var count = diagnoses.Count(); if (this.ModelState.IsValid) { var diagnosis = new Diagnosis { DiagnosisId = ++count, PatientId = patient.Id, Patient = patient, Type = model.Type, Complications = model.Complications, Details = model.Details }; this.context.Add(diagnosis); await this.context.SaveChangesAsync(); return(this.RedirectToAction("Index", new { patientId = patient.Id })); } this.ViewBag.Patient = patient; return(this.View(model)); }