public IEnumerable <GetPrescriptionResponse> GetPresciptions() { var list = new List <GetPrescriptionResponse>(); using (var con = new SqlConnection("Data Source=db-mssql ;Initial Catalog=s16424; Integrated Security = True")) using (var com = new SqlCommand()) { com.Connection = con; com.CommandText = "select IdPrescription, Date, DueDate, Patient.LastName a, Doctor.LastName b " + "FROM Prescription INNER JOIN Doctor ON Prescription.IdDoctor = Doctor.IdDoctor " + "INNER JOIN Patient ON Prescription.IdPatient = Patient.IdPatient;"; con.Open(); var dr = com.ExecuteReader(); while (dr.Read()) { var Pre = new GetPrescriptionResponse(); Pre.IdPrescription = (int)dr["IdPrescription"]; Pre.Date = (DateTime)dr["Date"]; Pre.DueDate = (DateTime)dr["DueDate"]; Pre.PatientLastName = dr["a"].ToString(); Pre.DoctorLastName = dr["b"].ToString(); list.Add(Pre); } } return(list); }
public IActionResult GetPrescription(string idprescription) { GetPrescriptionResponse response = new GetPrescriptionResponse(); using (SqlConnection con = new SqlConnection(ConString)) using (SqlCommand com = new SqlCommand()) { com.Connection = con; con.Open(); com.CommandText = "SELECT * from prescription where idprescription=@idprescription "; com.Parameters.AddWithValue("idprescription", idprescription); var reader = com.ExecuteReader(); if (reader.Read()) { response.IdPrescription = (int)reader["IdPrescription"]; response.IdPatient = (int)reader["IdPatient"]; response.IdDoctor = (int)reader["IdDoctor"]; response.Date = (DateTime)reader["Date"]; response.DueDate = (DateTime)reader["DueDate"]; response.Medicaments = new List <Medicament>(); } else { return(BadRequest("Brak takiej recepty")); } reader.Close(); com.Parameters.Clear(); com.CommandText = "SELECT m.name, m.description, m.type FROM prescription p INNER JOIN prescription_medicament pm ON pm.idprescription = p.idprescription " + " INNER JOIN medicament m ON pm.idmedicament = m.Idmedicament where p.idprescription = @idprescription "; com.Parameters.AddWithValue("idprescription", idprescription); reader = com.ExecuteReader(); while (reader.Read()) { response.Medicaments.Add( new Medicament { Name = reader["Name"].ToString(), Type = reader["Type"].ToString(), Description = reader["Description"].ToString() }); } } return(Ok(response)); }
public GetPrescriptionResponse GetPrescription(int Id) { var response = new GetPrescriptionResponse(); using (var con = new SqlConnection(ConString)) using (SqlCommand com = new SqlCommand()) { com.Connection = con; com.CommandText = "select IdPrescription, Date, DueDate, IdPatient, IdDoctor from Prescription where IdPrescription=@prescription"; com.Parameters.AddWithValue("prescription", Id); con.Open(); var dr = com.ExecuteReader(); if (dr.Read()) { response.IdPrescription = int.Parse(dr["IdPrescription"].ToString()); response.Date = dr["Date"].ToString(); response.DueDate = dr["DueDate"].ToString(); response.IdPatient = int.Parse(dr["IdPatient"].ToString()); response.IdDoctor = int.Parse(dr["IdDoctor"].ToString()); } return(response); } }