コード例 #1
0
        public IActionResult GetMediciment(string id)
        {
            Mediciment mediciment = _dbService.FindMedicimentsWithPrescr(id);

            if (mediciment == null)
            {
                return(NotFound("Mediciment not found"));
            }
            return(Ok(mediciment));
        }
コード例 #2
0
        public Mediciment FindMedicimentsWithPrescr(string id)
        {
            Mediciment mediciment = null;

            using (var con = new SQLiteConnection(dbConString))
                using (var com = con.CreateCommand())
                {
                    com.CommandText = "select * from Mediciament where IdMediciment = @id";
                    com.Parameters.AddWithValue("id", id);
                    con.Open();
                    using (var dr = com.ExecuteReader())
                    {
                        if (dr.Read())
                        {
                            mediciment = new Mediciment();
                            mediciment.IdMediciment = int.Parse(dr["IdMediciment"].ToString());
                            mediciment.Name         = dr["Name"].ToString();
                            mediciment.Decription   = dr["Description"].ToString();
                            mediciment.Type         = dr["Type"].ToString();

                            com.Reset();
                            com.CommandText = "Select p.* from Mediciment" +
                                              "join Prescription_Mediciment pm on pm.IdMediciment = @medId" +
                                              "join Prescription p on p.IdPrescription = pm.IdPrescription";
                            com.Parameters.AddWithValue("medId", id);
                            using (var dr2 = com.ExecuteReader())
                            {
                                while (dr.Read())
                                {
                                    var per = new Prescription();
                                    per.IdPrescription = int.Parse(dr["IdPrescription"].ToString());
                                    per.Date           = dr["Date"].ToString();
                                    per.DueDate        = dr["DueDate"].ToString();
                                    mediciment.Prescriptions.Add(per);
                                }
                            }
                        }
                    }
                }
            return(mediciment);
        }