Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (var ctx = new ScheduleContext())
            {
                if (comboBox1.SelectedItem.ToString() == "" || comboBox2.SelectedItem.ToString() == "" || comboBox3.SelectedItem.ToString() == "")
                {
                    MessageBox.Show("Missing required input from dropdown menu.", "Missing input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    int groupId     = Convert.ToInt32(comboBox1.SelectedValue);
                    int courseId    = Convert.ToInt32(comboBox2.SelectedValue);
                    int professorId = Convert.ToInt32(comboBox3.SelectedValue);
                    if (ctx.GroupCourseProfessors.Any(gcp => gcp.GroupId == groupId && gcp.CourseId == courseId && gcp.ProfessorId == professorId))
                    {
                        this.Close();
                        return;
                    }

                    var g = new GroupCourseProfessor
                    {
                        GroupId     = groupId,
                        CourseId    = courseId,
                        ProfessorId = professorId,
                        Timeslots   = Convert.ToInt32(textBox1.Text)
                    };

                    ctx.GroupCourseProfessors.Add(g);
                    ctx.SaveChanges();
                    this.Close();
                }
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (var ctx = new ScheduleContext())
            {
                if (comboBox1.SelectedItem.ToString() == "" || comboBox2.SelectedItem.ToString() == "" || comboBox3.SelectedItem.ToString() == "")
                {
                    MessageBox.Show("Missing required input from dropdown menu.", "Missing input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    int groupId = Convert.ToInt32(comboBox1.SelectedValue);
                    int courseId = Convert.ToInt32(comboBox2.SelectedValue);
                    int professorId = Convert.ToInt32(comboBox3.SelectedValue);
                    if (ctx.GroupCourseProfessors.Any(gcp => gcp.GroupId == groupId && gcp.CourseId == courseId && gcp.ProfessorId == professorId))
                    {
                        this.Close();
                        return;
                    }

                    var g = new GroupCourseProfessor
                    {
                        GroupId = groupId,
                        CourseId = courseId,
                        ProfessorId = professorId,
                        Timeslots = Convert.ToInt32(textBox1.Text)
                    };

                    ctx.GroupCourseProfessors.Add(g);
                    ctx.SaveChanges();
                    this.Close();
                }
            }
        }