public IActionResult Put([FromBody] PatientViewModel m) { // return generic HTTP Status 500 if client payload is invalid if (m == null) { return(new StatusCodeResult(500)); } //handling the insert var patient = new Patient(); //properties taken from request patient.Name = m.Name; patient.DOB = m.DOB; patient.Gender = m.Gender; patient.Address = m.Address; //properties set from server-side //TODO : Change when user module is introduced patient.Id = Guid.NewGuid(); patient.CreatedDate = DateTime.Now; patient.LastModifiedDate = DateTime.Now; //Adding the admin as foreign key patient.CreatedByUserId = DbContext.Users.Where(u => u.UserName == "Admin") .FirstOrDefault().Id; //adding the patient to the database DbContext.Patients.Add(patient); //persist to DB DbContext.SaveChanges(); // return created patient back to client return(new JsonResult(patient.Adapt <PatientViewModel>(), new JsonSerializerOptions { WriteIndented = true })); }