public IActionResult PostWithGeneralInformation(int id, [FromForm] GeneralInformationView generalInformationView) { try { if (id == 0) { return(BadRequest("id is zero")); } if (generalInformationView == null) { return(BadRequest("Owner object is null")); } if (!ModelState.IsValid) { return(BadRequest("Invalid model object")); } _patientRepository.InsertGeneralInformation(id, generalInformationView.ViewToEntity()); return(Ok()); } catch (Exception ex) { return(StatusCode(500, string.Format("Internal server error. Message error: {0}", ex.Message))); } }
public IActionResult Put([FromBody] GeneralInformationView generalInformationView) { try { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } var elem = _generalInformationRepository.GetBy(t => t.Id == generalInformationView.Id); if (elem != null) { elem.Bithday = generalInformationView.Birthday; elem.Weight = generalInformationView.Weight; elem.Height = generalInformationView.Height; elem.ArterialPressure = generalInformationView.ArterialPressure; elem.BloodType = generalInformationView.BloodType; _generalInformationRepository.Update(elem); return(Ok()); } return(NotFound()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public static GeneralInformation ViewToEntity(this GeneralInformationView view) { if (view != null) { return(new GeneralInformation { Id = view.Id, Bithday = view.Birthday, Weight = view.Weight, Height = view.Height, ArterialPressure = view.ArterialPressure, BloodType = view.BloodType, PatientId = view.PatientId, Fluorographies = view.Fluorographies.ViewToEntity() ?? new List <Fluorography>(), VaccinationStatuses = view.VaccinationStatuses.ViewToEntity() ?? new List <VaccinationStatus>(), SurgicalIntervention = view.SurgicalIntervention.ViewToEntity() ?? new List <SurgicalIntervention>() }); } return(null); }