public async Task <IActionResult> Create(Int32?patientId, DiagnosesCreateViewModel model)
        {
            if (patientId == null)
            {
                return(this.NotFound());
            }
            var patient = await this._context.Patients
                          .SingleOrDefaultAsync(x => x.Id == patientId);

            if (patient == null)
            {
                return(this.NotFound());
            }


            if (ModelState.IsValid)
            {
                var diagnosisId = this._context.Diagnoses.Any() ? this._context.Diagnoses.Max(x => x.DiagnosisId) + 1 : 1;
                var diagnosis   = new Diagnosis
                {
                    PatientId     = patient.Id,
                    DiagnosisId   = diagnosisId,
                    Type          = model.Type,
                    Complications = model.Complications,
                    Details       = model.Details
                };

                _context.Add(diagnosis);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", new { patientId = patient.Id }));
            }
            this.ViewBag.Patient = patient;
            return(this.View(model));
        }
        public async Task <IActionResult> Edit(Int32?patientId, Int32?diagnosisId, DiagnosesCreateViewModel model)
        {
            if (patientId == null || diagnosisId == null)
            {
                return(NotFound());
            }

            var diagnosis = await _context.Diagnoses.SingleOrDefaultAsync(m => m.DiagnosisId == diagnosisId && m.PatientId == patientId);

            if (diagnosis == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                diagnosis.Type          = model.Type;
                diagnosis.Details       = model.Details;
                diagnosis.Complications = model.Complications;
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", new { patientId = patientId }));
            }

            return(View(diagnosis));
        }