private void btnUpdate_Click(object sender, EventArgs e)
        {
            var  progarm       = cbProgram.SelectedItem as Programs;
            var  classSchedule = cbClassesSchedule.SelectedItem as ClassSchedule;
            bool updated       = false;

            if (classSchedule.Id == 1)
            {
                MorningStudent student = new MorningStudent
                {
                    StudentId       = int.Parse(txtSId.Text.Trim()),
                    Name            = txtName.Text.Trim(),
                    FatherName      = txtFatherName.Text.Trim(),
                    Address         = txtAddress.Text.Trim(),
                    DateOfBirth     = dtpDoB.Value,
                    DateOfAdmission = dtpDoAdmission.Value,
                    ProgramID       = progarm.ProgramsId,
                    ClassScheduleID = classSchedule.Id
                };
                updated = studentCRUD.UpdateStudent(student);
            }
            else if (classSchedule.Id == 2)
            {
                EveningStudent student = new EveningStudent
                {
                    StudentId       = int.Parse(txtSId.Text.Trim()),
                    Name            = txtName.Text.Trim(),
                    FatherName      = txtFatherName.Text.Trim(),
                    Address         = txtAddress.Text.Trim(),
                    DateOfBirth     = dtpDoB.Value,
                    DateOfAdmission = dtpDoAdmission.Value,
                    ProgramID       = progarm.ProgramsId,
                    ClassScheduleID = classSchedule.Id
                };
                updated = studentCRUD.UpdateStudent(student);
            }
            else if (classSchedule.Id == 3)
            {
                WeekendStudent student = new WeekendStudent
                {
                    StudentId       = int.Parse(txtSId.Text.Trim()),
                    Name            = txtName.Text.Trim(),
                    FatherName      = txtFatherName.Text.Trim(),
                    Address         = txtAddress.Text.Trim(),
                    DateOfBirth     = dtpDoB.Value,
                    DateOfAdmission = dtpDoAdmission.Value,
                    ProgramID       = progarm.ProgramsId,
                    ClassScheduleID = classSchedule.Id
                };
                updated = studentCRUD.UpdateStudent(student);
            }
            if (updated)
            {
                MessageBox.Show("Updated Successfully");
            }
        }
        static void Main(string[] args)
        {
            Student nadia = new DailyStudent("Nadia", "Comanici");
            Student ionel = new EveningStudent("Ionel", "Ionescu");
            Student maria = new WeekendStudent("Maria", "Popescu");

            List <Student> students = new List <Student>();

            students.Add(nadia);
            students.Add(ionel);
            students.Add(maria);

            foreach (var student in students)
            {
                Console.WriteLine($"{student.FirstName} are nevoie de {student.GetMinimumCreditPointsToPromote()} credite.");
            }
        }
        public bool UpdateStudent(WeekendStudent _student)
        {
            var students = context.WeekendStudents.ToList();

            foreach (var studnet in students)
            {
                if (studnet.StudentId == _student.StudentId)
                {
                    var student = context.WeekendStudents.Single(s => s.StudentId == _student.StudentId);
                    student.Name            = _student.Name;
                    student.FatherName      = _student.FatherName;
                    student.Address         = _student.Address;
                    student.DateOfBirth     = _student.DateOfBirth;
                    student.DateOfAdmission = _student.DateOfAdmission;
                    student.ProgramID       = _student.ProgramID;
                    student.ClassScheduleID = _student.ClassScheduleID;

                    context.SaveChanges();
                    return(true);
                }
            }
            AddStudent(_student);
            return(true);
        }
 public bool AddStudent(WeekendStudent _weeklyStudent)
 {
     context.WeekendStudents.Add(_weeklyStudent);
     context.SaveChanges();
     return(true);
 }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                Programs       program = cbProgram.SelectedItem as Programs;
                StudentFactory student;
                MorningStudent morningStudent = null;
                EveningStudent eveningStudent = null;
                WeekendStudent weeklyStudent  = null;
                bool           insert         = false;

                ClassSchedule classSchedule = cbClassesSchedule.SelectedItem as ClassSchedule;

                if (classSchedule.Id == 1)
                {
                    student        = new MorningStudentFactory();
                    morningStudent = (MorningStudent)student.GetStudent();
                }
                else if (classSchedule.Id == 2)
                {
                    student        = new EveningStudentFactory();
                    eveningStudent = (EveningStudent)student.GetStudent();
                }
                else if (classSchedule.Id == 3)
                {
                    student       = new WeekendStudentFactory();
                    weeklyStudent = (WeekendStudent)student.GetStudent();
                }
                else
                {
                    student = null;
                }

                if (student != null)
                {
                    if (classSchedule.Id == 1)
                    {
                        morningStudent.Name            = txtName.Text.Trim();
                        morningStudent.FatherName      = txtFatherName.Text.Trim();
                        morningStudent.Address         = txtAddress.Text.Trim();
                        morningStudent.DateOfBirth     = dtpDoB.Value;
                        morningStudent.DateOfAdmission = dtpDoAdmission.Value;
                        morningStudent.ProgramID       = program.ProgramsId;
                        morningStudent.ClassScheduleID = classSchedule.Id;

                        insert = studentCRUD.AddStudent(morningStudent);
                        ClearTextBoxes();
                    }
                    else if (classSchedule.Id == 2)
                    {
                        eveningStudent.Name            = txtName.Text.Trim();
                        eveningStudent.FatherName      = txtFatherName.Text.Trim();
                        eveningStudent.Address         = txtAddress.Text.Trim();
                        eveningStudent.DateOfBirth     = dtpDoB.Value;
                        eveningStudent.DateOfAdmission = dtpDoAdmission.Value;
                        eveningStudent.ProgramID       = program.ProgramsId;
                        eveningStudent.ClassScheduleID = classSchedule.Id;

                        insert = studentCRUD.AddStudent(eveningStudent);
                        ClearTextBoxes();
                    }
                    else if (classSchedule.Id == 3)
                    {
                        weeklyStudent.Name            = txtName.Text.Trim();
                        weeklyStudent.FatherName      = txtFatherName.Text.Trim();
                        weeklyStudent.Address         = txtAddress.Text.Trim();
                        weeklyStudent.DateOfBirth     = dtpDoB.Value;
                        weeklyStudent.DateOfAdmission = dtpDoAdmission.Value;
                        weeklyStudent.ProgramID       = program.ProgramsId;
                        weeklyStudent.ClassScheduleID = classSchedule.Id;

                        insert = studentCRUD.AddStudent(weeklyStudent);
                        ClearTextBoxes();
                    }
                }
                else
                {
                    MessageBox.Show("Error!");
                }

                if (insert)
                {
                    MessageBox.Show("New Student added successfully.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }