Пример #1
0
        public IActionResult GetPrescriptions(string nazwisko)
        {
            PrescriptionDBservice service = new PrescriptionDBservice();

            _dbService.clear();

            using (var con = new SqlConnection("Data Source=db-mssql;Initial Catalog=s18836;Integrated Security=True"))
                using (var com = new SqlCommand())
                {
                    com.Connection = con;
                    con.Open();
                    string text;

                    if (nazwisko == null)
                    {
                        text = "SELECT IdPrescription,DATE,DueDate,PATIENT.LastName AS PATIENTLASTNAME, Doctor.LastName AS DOCTORLASTNAME FROM Prescription INNER JOIN DOCTOR ON Doctor.IdDoctor = Prescription.IdDoctor INNER JOIN Patient ON Patient.IdPatient = Prescription.IdPatient ORDER BY DATE DESC;";
                    }
                    else
                    {
                        text = $"SELECT IdPrescription, DATE, DueDate, PATIENT.LastName AS PATIENTLASTNAME, Doctor.LastName AS DOCTORLASTNAME FROM Prescription INNER JOIN DOCTOR ON Doctor.IdDoctor = Prescription.IdDoctor INNER JOIN Patient ON Patient.IdPatient = Prescription.IdPatient WHERE DOCTOR.LASTNAME = '{nazwisko}'; ";
                    }



                    com.CommandText = "USE [S18836];" + text;
                    var dr = com.ExecuteReader();

                    while (dr.Read())
                    {
                        var response = new prescriptionsresponse();
                        response.IdPrescription  = (int)dr["IdPrescription"];
                        response.Date            = (DateTime)dr["Date"];
                        response.DueDate         = (DateTime)dr["DueDate"];
                        response.PatientLastName = dr["PATIENTLASTNAME"].ToString();
                        response.DoctorLastName  = dr["DOCTORLASTNAME"].ToString();

                        _dbService.add_prescription(response);
                    }



                    return(Ok(_dbService.get_response())); //(com.CommandText);
                }
        }
Пример #2
0
 public void add_prescription(prescriptionsresponse prescription)
 {
     responses.Add(prescription);
 }