public ActionResult DeleteConfirmed(int id)
        {
            Perscription perscription = db.Perscriptions.Find(id);

            db.Perscriptions.Remove(perscription);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "PetId,MedicationId,Quantity,Direction,Id")] Perscription perscription)
 {
     if (ModelState.IsValid)
     {
         db.Entry(perscription).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MedicationId = new SelectList(db.Medications, "Id", "Name", perscription.MedicationId);
     ViewBag.PetId        = new SelectList(db.Patients, "PatientId", "Name", perscription.PetId);
     return(View(perscription));
 }
        // GET: Perscriptions/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Perscription perscription = db.Perscriptions.Find(id);

            if (perscription == null)
            {
                return(HttpNotFound());
            }
            return(View(perscription));
        }
        // GET: Perscriptions/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Perscription perscription = db.Perscriptions.Find(id);

            if (perscription == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MedicationId = new SelectList(db.Medications, "Id", "Name", perscription.MedicationId);
            ViewBag.PetId        = new SelectList(db.Patients, "PatientId", "Name", perscription.PetId);
            return(View(perscription));
        }
Exemple #5
0
        public IActionResult GetPrescriptions()
        {
            var list = new List <String>();

            using (SqlConnection con = new SqlConnection("Data Source=db-mssql;Initial Catalog=s18705;Integrated Security=True"))
                using (SqlCommand com = new SqlCommand())
                {
                    com.Connection  = con;
                    com.CommandText = "Select prescription.IdPrescription, prescription.Date, prescription.DueDate, Patient.LastName, Doctor.LastName FROM prescription INNER JOIN Doctor ON prescription.IdDoctor = Doctor.IdDoctor INNER JOIN Patient ON prescription.IdPatient = Patient.IdPatient";


                    con.Open();
                    SqlDataReader dr = com.ExecuteReader();

                    while (dr.Read())
                    {
                        var per = new Perscription();
                        var doc = new Doctor();
                        var pat = new Patient();

                        try
                        {
                            //per.IdPerscription = int.Parse(dr["IdPerscription"]).ToString());
                            per.Date     = DateTime.Parse(dr["Date"].ToString());
                            per.DueDate  = DateTime.Parse(dr["DueDate"].ToString());
                            pat.LastName = dr["LastName"].ToString();
                            doc.LastName = dr["LastName"].ToString();
                            list.Add(per.ToString());
                            list.Add(pat.ToString());
                            list.Add(doc.ToString());
                        }
                        catch (ArgumentNullException ex)
                        {
                            return(NotFound());
                        }
                    }
                }
            return(Ok(list));
        }
        public IActionResult getPrescripton(int IdPrescription)
        {
            var pres = new Perscription();

            string sqlConString = "Data Source=db-mssql;Initial Catalog=s19322;Integrated Security=True";

            using (SqlConnection con = new SqlConnection(sqlConString))
                using (SqlCommand comand = new SqlCommand())
                {
                    comand.Connection  = con;
                    comand.CommandText = "select * from Prescription p inner join Prescription_Medicament pm on p.IdPrescription = pm.IdPrescription inner join Medicament m on m.IdMedicament = pm.IdMedicament where p.IdPrescription=@IdPrescription";


                    comand.Parameters.AddWithValue("IdPrescription", IdPrescription);

                    con.Open();
                    SqlDataReader dr = comand.ExecuteReader();


                    while (dr.Read())
                    {
                        pres.IdPrescription = (int)dr["IdPrescription"];
                        pres.Date           = (DateTime)dr["Date"];
                        pres.DueDate        = (DateTime)dr["DueDate"];
                        pres.IdDoctor       = (int)dr["IdDoctor"];
                        pres.IdPatient      = (int)dr["IdPatient"];
                        var med = new Medicament()
                        {
                            Description  = dr["Description"].ToString(),
                            Name         = dr["Name"].ToString(),
                            IdMedicament = (int)dr["IdMedicament"],
                            Type         = dr["Type"].ToString()
                        };
                        pres.MedicineList.Add(med);//zabrakło czasu aby naprawic
                    }
                }
            return(Ok(pres));
        }