public IActionResult PutHeartUltrasound([FromBody] HeartUltrasoundView heartUltrasound) { try { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } var elem = _heartUltrasoundRepository.GetBy(t => t.Id == heartUltrasound.Id); if (elem != null) { elem.Info = heartUltrasound.Info; _heartUltrasoundRepository.Update(elem); return(Ok()); } return(NotFound()); } catch { return(BadRequest()); } }
public IActionResult PostWithHeartUltrasound(int id, [FromForm] HeartUltrasoundView heartUltrasoundView) { try { if (id == 0) { return(BadRequest("id is zero")); } if (heartUltrasoundView == null) { return(BadRequest("Owner object is null")); } if (!ModelState.IsValid) { return(BadRequest("Invalid model object")); } _medicalExaminationRepository.InsertHeartUltrasound(id, heartUltrasoundView.ViewToEntity()); return(Ok()); } catch (Exception ex) { return(StatusCode(500, string.Format("Internal server error. Message error: {0}", ex.Message))); } }
public static HeartUltrasound ViewToEntity(this HeartUltrasoundView view) { if (view != null) { return(new HeartUltrasound { Id = view.Id, Info = view.Info, MedicalExaminationId = view.MedicalExaminationId }); } return(null); }
public IActionResult PostHeartUltrasound([FromBody] HeartUltrasoundView heartUltrasound) { try { if (heartUltrasound == null) { return(BadRequest("Owner object is null")); } if (!ModelState.IsValid) { return(BadRequest("Invalid model object")); } heartUltrasound.Id = 0; _heartUltrasoundRepository.Insert(heartUltrasound.ViewToEntity()); return(Ok()); } catch (Exception ex) { return(StatusCode(500, "Internal server error" + ex.Message)); } }