Ejemplo n.º 1
0
        private void button5_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow.Index != -1)
            {
                using (var cnt = new SageBookDbContext())
                {
                    int    id    = int.Parse(dataGridView1.CurrentRow.Cells["id"].Value.ToString());
                    var    sage  = cnt.Sages.Where(s => s.id == id);
                    string name  = textBox3.Text;
                    int    age   = Int32.Parse(textBox4.Text);
                    byte[] photo = Sage.ImageToByteArray(pictureBox1.Image);
                    string city  = textBox7.Text;

                    updateSageInfo(id, name, age, photo, city);

                    //var booksIds = cnt.Books.Where(b => b.Sages.);
                    //Sage sage = new Sage() { name = name, age = age, city = city, photo = Sage.ImageToByteArray(photo) };
                    var dbSage = cnt.Sages.First(b => b.id == id);
                    dbSage.name  = name;
                    dbSage.age   = age.ToString();
                    dbSage.photo = photo;
                    dbSage.city  = city;
                    //var sages = cnt.Sages.Where(s => sagesId.Contains(s.id)).ToList();
                    //dbBook.Sages = dbBook.Sages;
                    //dbBook.Sages = sages;

                    cnt.SaveChanges();
                }
            }

            loadSageRecords();
        }
Ejemplo n.º 2
0
        private void button4_Click(object sender, EventArgs e)
        {
            string name  = textBox3.Text;
            string age   = textBox4.Text;
            var    photo = pictureBox1.Image;
            string city  = textBox7.Text;

            // TODO: check arguments

            using (var cnt = new SageBookDbContext())
            {
                //var booksIds = cnt.Books.Where(b => b.Sages.);
                Sage sage = new Sage()
                {
                    name = name, age = age, city = city, photo = Sage.ImageToByteArray(photo)
                };

                cnt.Sages.Add(sage);
                cnt.SaveChanges();
            }
            loadSageRecords();
        }