public Task<Patient> UpdatePatientAsync(Patient patient) { return Task.Run(() => { if (string.IsNullOrEmpty(patient.Id)) patient.Id = Guid.NewGuid().ToString(); _dbContext.Patients.AddOrUpdate(patient); return patient; }); }
public Task<Patient> CreatePatientAsync(Patient patient) { return Task.Run(() => { patient.Id = Guid.NewGuid().ToString(); _dbContext.Patients.Add(patient); return patient; }); }
public async Task<IHttpActionResult> PutPatient(Patient patient) { try { if (string.IsNullOrEmpty(patient?.Id)) return BadRequest(); Patient retPatient = await _repository.UpdatePatientAsync(patient); if (retPatient == null) return BadRequest(); return Ok(retPatient); } catch (Exception exception) { this.Logger.LogError(exception.ToString()); return InternalServerError(); } }
public async Task<IHttpActionResult> PostPatient(Patient patient) { try { if (patient == null) return BadRequest(); Patient retPatent = await _repository.CreatePatientAsync(patient); if (retPatent == null) return BadRequest(); return Created("", retPatent); } catch (Exception exception) { this.Logger.LogError(exception.ToString()); return InternalServerError(); } }