Esempio n. 1
0
        public void RemoveMedicineRelation(int diagnosisId, string medicineName)
        {
            if (string.IsNullOrEmpty(medicineName))
            {
                return;
            }

            using (var db = new ZooContext())
            {
                MedicineDiagnosisRelation medicineRelation =
                    db.MedicineDiagnosisRelation.SingleOrDefault(m => m.Medicine.MedicineName == medicineName &&
                                                                 m.DiagnosisId == diagnosisId);

                db.Entry(medicineRelation).State = EntityState.Deleted;

                db.SaveChanges();
            }
        }
Esempio n. 2
0
        /*---------------------------------Methods regarding other---------------------------------*/
        public void AddMedicineDiagnosisRelation(int diagnosisId, string medicienname)
        {
            using (var db = new ZooContext())
            {
                Medicine medicine = db.Medicine.SingleOrDefault(m => m.MedicineName == medicienname);

                Diagnosis diagnosis = db.Diagnosis.SingleOrDefault(d => d.Id == diagnosisId);

                MedicineDiagnosisRelation mdr = new MedicineDiagnosisRelation()
                {
                    Medicine  = medicine,
                    Diagnosis = diagnosis
                };

                db.MedicineDiagnosisRelation.Add(mdr);

                db.SaveChanges();
            }
        }
Esempio n. 3
0
        public bool DeleteBooking(int bookingId)
        {
            bool removed = false;

            using (var db = new ZooContext())
            {
                //Get all diagnosies for the booking
                var diagnosies = db.Diagnosis.Where(d => d.BookingId == bookingId).ToList();

                //Get and remove all connections between medicine and diagonsis
                //and remove all diagnosises
                for (int i = diagnosies.Count - 1; i >= 0; i--)
                {
                    Diagnosis diagnois = diagnosies[i];

                    var medecineDiagonsis = db.MedicineDiagnosisRelation
                                            .Where(r => r.DiagnosisId == diagnois.Id)
                                            .ToList();

                    for (int x = medecineDiagonsis.Count - 1; x >= 0; x--)
                    {
                        MedicineDiagnosisRelation md = medecineDiagonsis[x];
                        db.Entry(md).State = EntityState.Deleted;
                    }

                    db.Entry(diagnois).State = EntityState.Deleted;
                }

                //Remove booking
                Booking booking = db.Booking.SingleOrDefault(b => b.Id == bookingId);
                db.Booking.Attach(booking);
                db.Booking.Remove(booking);

                //save changes
                db.SaveChanges();

                removed = true;
            }

            return(removed);
        }