Пример #1
0
 private void button6_Click(object sender, EventArgs e)
 {
     using (MyDbContext cnt = new MyDbContext())
     {
         Sage s = new Sage()
         {
             Birthday = DateTime.Today
         };
         Form3 form = new Form3(s);
         form.ShowDialog();
         cnt.Sages.Add(s);
         cnt.SaveChanges();
     }
     loadData();
 }
Пример #2
0
        private void button8_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count < 1)
            {
                return;
            }

            int index  = dataGridView3.SelectedRows[0].Index;
            int idSage = (int)dataGridView3["SageId", index].Value;
            int idBook = (int)dataGridView3["BookId", index].Value;

            using (MyDbContext cnt = new MyDbContext())
            {
                Sage s = cnt.Sages.Find(idSage);
                s.Books.Remove(s.Books.Where(x => x.Id == idBook).FirstOrDefault());
                cnt.SaveChanges();
            }
            loadData();
        }
Пример #3
0
 public Form3(Sage sage)
 {
     InitializeComponent();
     s = sage;
 }