Пример #1
0
        private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            HospitalDBEntities db = new HospitalDBEntities();

            // TODO: Replace hard coded values with Text Inputs
            db.Doctors.Add(new Doctor()
            {
                Name           = "New Doc",
                Specialization = "New Spec"
            });

            db.SaveChanges();

            MessageBox.Show("New Record added!");

            this.dataGridDocs.ItemsSource = db.Doctors.ToList();
        }
Пример #2
0
        private void ShowDoctors()
        {
            HospitalDBEntities db = new HospitalDBEntities();

            this.dataGridDocs.ItemsSource = db.Doctors.ToList();

            var r = from d in db.Doctors
                    where d.Name.EndsWith("Ali")
                    select d;

            foreach (var item in r)
            {
                Console.WriteLine(item.Name);
            }

            //this.dataGridDocs.ItemsSource = r.ToList();
        }
Пример #3
0
        public EF_Joins()
        {
            InitializeComponent();

            HospitalDBEntities db = new HospitalDBEntities();

            var r = from a in db.Appointments
                    select new
            {
                AppID    = a.Id,
                DoctorID = a.dID,
                a.Doctor.Name,
                a.Doctor.Specialization,
                a.AppointmentDate
            };

            this.dataGridAppointments.ItemsSource = r.ToList();
        }
Пример #4
0
        private void DeleteRecord()
        {
            HospitalDBEntities db = new HospitalDBEntities();
            var r = from d in db.Doctors
                    where d.Id == 1
                    select d;

            Doctor doctorObj = r.SingleOrDefault();

            if (doctorObj != null)
            {
                db.Doctors.Remove(doctorObj);
                db.SaveChanges();
            }
            else
            {
                MessageBox.Show("Doctor does not exist!");
            }
        }
Пример #5
0
        private void UpdateDoctor()
        {
            HospitalDBEntities db = new HospitalDBEntities();
            var r = from d in db.Doctors
                    where d.Id == 2
                    select d;

            Doctor doctorObj = r.SingleOrDefault();

            if (doctorObj != null)
            {
                doctorObj.Name = "Updated Doctor";
                db.SaveChanges();
                MessageBox.Show("Record updated!");
                this.ShowDoctors();
            }
            else
            {
                MessageBox.Show("Doctor does not exist!");
            }
        }