Beispiel #1
0
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            if (selectedTest == null)
            {
                MessageBox.Show("Элемент не выбран");
                return;
            }
            selectedTest.Name     = tbName.Text;
            selectedTest.PassMark = Convert.ToInt16(tbPassMark.Text);

            var updateTest = new Test()
            {
                id       = (int)selectedTest.id,
                Name     = selectedTest.Name,
                PassMark = (short)selectedTest.PassMark
            };

            using (StudentTestingEntities1 db = new StudentTestingEntities1())
            {
                db.Test.Add(updateTest);
                db.Entry(updateTest).State = EntityState.Modified;
                db.SaveChanges();
            }
            Clear();
            LoadData();
        }
Beispiel #2
0
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            if (selectedTest == null)
            {
                MessageBox.Show("Элемент не выбран");
                return;
            }
            var deleteTest = new Test()
            {
                id       = (int)selectedTest.id,
                Name     = selectedTest.Name,
                PassMark = (short)selectedTest.PassMark
            };

            using (StudentTestingEntities1 db = new StudentTestingEntities1())
            {
                db.Entry(deleteTest).State = EntityState.Deleted;
                db.SaveChanges();
            }
            Clear();
            LoadData();
        }
        private void Update(List <Question> updateList)
        {
            using (StudentTestingEntities1 db = new StudentTestingEntities1())
            {
                try
                {
                    updateList.ForEach(o =>
                    {
                        var entity = db.Question.Where(z => z.id == o.id).FirstOrDefault();
                        if (entity == null)
                        {
                            return;
                        }

                        db.Entry(entity).CurrentValues.SetValues(o);
                    });
                    db.SaveChanges();
                }
                catch (Exception j)
                {
                    Console.Write(j.ToString());
                }
            }
        }