Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (var ctx = new ScheduleContext())
            {
                if (textBox2.Text == "")
                {
                    MessageBox.Show("Missing required input.", "Missing input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    var prof = new Professor
                    {
                        // Podesi input, automatski increase ID
                        Name = textBox2.Text.ToString(),
                    };

                    ctx.Professors.Add(prof);
                    ctx.SaveChanges();

                    //Adding ProfessorTimeRestriction

                    foreach (var r in restrictions)
                    {
                        var restriction = new ProfessorTimeRestriction
                        {
                            ProfessorId = prof.Id,
                            TimeslotId = r,
                        };
                        ctx.ProfessorTimeRestrictions.Add(restriction);
                        ctx.SaveChanges();
                    }
                    this.Close();
                }
            }
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (var ctx = new ScheduleContext())
            {
                if (textBox2.Text == "")
                {
                    MessageBox.Show("Missing required input.", "Missing input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    var prof = new Professor
                    {
                        // Podesi input, automatski increase ID
                        Name = textBox2.Text.ToString(),
                    };

                    ctx.Professors.Add(prof);
                    ctx.SaveChanges();

                    //Adding ProfessorTimeRestriction

                    foreach (var r in restrictions)
                    {
                        var restriction = new ProfessorTimeRestriction
                        {
                            ProfessorId = prof.Id,
                            TimeslotId  = r,
                        };
                        ctx.ProfessorTimeRestrictions.Add(restriction);
                        ctx.SaveChanges();
                    }
                    this.Close();
                }
            }
        }