Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. // POST: Diagnoses/Create
  2.         // To protect from overposting attacks, please enable the specific properties you want to bind to, for
  3.         // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
  4.         [HttpPost]
  5.         [ValidateAntiForgeryToken]
  6.         public async Task<IActionResult> Create(Int32? patientId, DiagnosesCreateModel model)
  7.         {
  8.             if (patientId == null)
  9.             {
  10.                 return this.NotFound();
  11.             }
  12.             var patient = await this._context.Patients.SingleOrDefaultAsync(x => x.Id == patientId);
  13.             if (patient == null)
  14.             {
  15.                 return this.NotFound();
  16.             }
  17.  
  18.             if (ModelState.IsValid)
  19.             {
  20.                 var diagnosis = new Diagnosis
  21.                 {
  22.                     PatientId = patient.Id,
  23.                     Type = model.Type,
  24.                     Complications = model.Complications,
  25.                     Details = model.Details
  26.                 };
  27.                 this._context.Add(diagnosis);
  28.                 await this._context.SaveChangesAsync();
  29.                 return this.RedirectToAction("Index", new { patientId = patient.Id });
  30.             }
  31.             this.ViewBag.Ward = patient;
  32.             return this.View(model);
  33.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement