Beispiel #1
0
        public void CanAddTeacherEmailInDb()
        {
            var    teacher = new TeacherRegisterController();
            string email   = "qqqqq@gmail";
            bool   result  = teacher.CheckEmailExists(email);

            Assert.IsTrue(result, "Teacher email not  exists in database and can  add");
        }
Beispiel #2
0
        public void CanNotAddTeacherEmailInDb()
        {
            var    teacher = new TeacherRegisterController();
            string email   = "laskjd@asmn";
            bool   result  = teacher.CheckEmailExists(email);

            Assert.IsFalse(result, "Teacher email exists in database and can not add");
        }
        //add  teacher in db and checks if info is correct
        void AddTeacherInDb()
        {
            //NAME
            try
            {
                teacherRegisterController.SetName(FullName);
                if (FullName.Split(' ').ToList().Count > 3)
                {
                    throw new Exception();
                }
                if (teacherRegisterController.TeacherNameExists(FullName))
                {
                    MessageBox.Show("Teacher already exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            catch
            {
                MessageBox.Show("Wrong Name Format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            // ADD BirthDate

            teacherRegisterController.AddBirthdate(Date);

            //Email
            if (teacherRegisterController.IsValidEmail(Email))
            {
                if (teacherRegisterController.CheckEmailExists(Email))
                {
                    teacherRegisterController.SetEmail(Email);
                }
                else
                {
                    MessageBox.Show("Email is already used!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("Email is not valid!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //ADD Phone
            if (teacherRegisterController.PhoneIsValid(PhoneNumber))
            {
                if (teacherRegisterController.CheckPhoneExists(PhoneNumber) == false)
                {
                    teacherRegisterController.SetPhone(PhoneNumber);
                }
                else
                {
                    MessageBox.Show("Phone number is already used!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("Phone number is not valid!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }



            //ADD EGN
            if (teacherRegisterController.IsValidEGN(EGN))
            {
                if (teacherRegisterController.CheckEGNExists(EGN) == false)
                {
                    teacherRegisterController.SetEGN(EGN);
                }
                else
                {
                    MessageBox.Show("EGN is already used!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("EGN is not valid!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                if (Subject.SelectedItem == null)
                {
                    MessageBox.Show("Please select a subject!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    teacherRegisterController.SetSubject(Subject.Text);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Please select a subject!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            teacherRegisterController.CommitChanged();
            MessageBox.Show("Success!", "Operation Completed", MessageBoxButtons.OK);
        }