コード例 #1
0
        public async Task <IActionResult> Edit(Int32?id, DiagnosisCreateModel model)
        {
            if (id == null)
            {
                return(this.NotFound());
            }

            var diagnosis = await this._context.Diagnoses.SingleOrDefaultAsync(m => m.DiagnosisId == id);

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

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

                return(RedirectToAction(nameof(Index), new { patientId = diagnosis.PatientId }));
            }
            this.ViewBag.Diagnosis = diagnosis;
            return(this.View(model));
        }
コード例 #2
0
        public async Task <IActionResult> Create(Int32?patientId, DiagnosisCreateModel model)
        {
            if (patientId == null)
            {
                return(this.NotFound());
            }

            var patient = await this._context.Patients
                          .Include(d => d.Diagnoses)
                          .SingleOrDefaultAsync(x => x.Id == patientId);

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

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

                return(RedirectToAction(nameof(Index), new { patientId = patient.Id }));
            }
            this.ViewBag.Patient = patient;
            return(this.View(model));
        }
コード例 #3
0
        // GET: Diagnoses/Edit/5
        public async Task <IActionResult> Edit(Int32?id, Int32?patientId)
        {
            if (id == null)
            {
                return(this.NotFound());
            }

            var diagnosis = await this._context.Diagnoses
                            .Include(p => p.Patient)
                            .SingleOrDefaultAsync(m => m.DiagnosisId == id && m.PatientId == patientId);

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

            var model = new DiagnosisCreateModel
            {
                Type          = diagnosis.Type,
                Complications = diagnosis.Complications,
                Details       = diagnosis.Details
            };

            this.ViewBag.Diagnosis = diagnosis;
            return(this.View(model));
        }