public void Create_RegisterValid_RedirectsToSessionIndex()
        {
            _sessionRepository.Setup(m => m.GetByDateToday()).Returns(_dummyContext.Session);
            _memberRepository.Setup(m => m.GetById(5)).Returns(_dummyContext.Member2Dagen);

            RedirectToActionResult action = _controller.Create(5) as RedirectToActionResult;

            Assert.Equal("Index", action?.ActionName);
            Assert.Equal("Session", action?.ControllerName);
        }
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            ClassModel Class = new ClassModel();

            Class.ClassDate   = datePicker.Value.ToString("yyyy-MM-dd");
            Class.StartTimeId = comboBoxStartTime.SelectedIndex + 1;
            Class.EndTimeId   = comboBoxEndTime.SelectedIndex + 1;
            Class.RoomNo      = textBoxRoomNo.Text;
            Class.SectionId   = section.Id;
            if (comboBoxClassType.SelectedIndex == 0)
            {
                Class.ClassType = ClassTypes.Lab;
            }
            else if (comboBoxClassType.SelectedIndex == 1)
            {
                Class.ClassType = ClassTypes.Theory;
            }
            else
            {
                try
                {
                    throw new Exception("Invalid class type");
                }catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            ClassController ccontroller = new ClassController();

            try
            {
                Class.IsValid();

                List <ClassModel> sameDayClasses = ccontroller.GetByDateAndFacultyId(Class.ClassDate, faculty.Id);
                //Console.WriteLine("Found " + sameDayClasses.Count + " classes");
                foreach (ClassModel model in sameDayClasses)
                {
                    //Console.WriteLine("start id: " + model.StartTimeId + " end id: " + model.EndTimeId);
                    //Console.WriteLine("this start: " + Class.StartTimeId + " this end: " + Class.EndTimeId);

                    if (Class.StartTimeId < model.EndTimeId && Class.StartTimeId >= model.StartTimeId)
                    {
                        throw new Exception("Class time clashes with another class on " + Class.ClassDate);
                    }
                    if (Class.EndTimeId <= model.EndTimeId && Class.EndTimeId > model.StartTimeId)
                    {
                        throw new Exception("Class time clashes with another class on " + Class.ClassDate);
                    }
                }
                //Console.WriteLine("Clash checking complete");
                try
                {
                    var createdClass = ccontroller.Create(Class);

                    string qrstring        = createdClass.Id.ToString() + "|" + section.SectionName.ToString() + "|" + createdClass.CreatedAt.ToString();
                    string encodedqrstring = Convert.ToBase64String(Encoding.UTF8.GetBytes(qrstring));
                    string decodedqrstring = (Encoding.UTF8.GetString(Convert.FromBase64String(encodedqrstring)));
                    //Console.WriteLine(decodedqrstring);
                    try
                    {
                        ccontroller.InsertQRCode(createdClass.Id, encodedqrstring);

                        SectionStudentController sscontroller = new SectionStudentController();
                        List <int> sectionStudentsId          = sscontroller.GetAllBySection(section.Id);

                        AttendanceController acontroller = new AttendanceController();

                        foreach (int StudentId in sectionStudentsId)
                        {
                            AttendanceModel attendance = new AttendanceModel();
                            attendance.ClassId   = createdClass.Id;
                            attendance.StudentId = StudentId;

                            try
                            {
                                acontroller.Create(attendance);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                            }
                        }
                        //Console.WriteLine("Created class id: " + createdClass.Id);
                        MessageBox.Show("Class added on " + (createdClass.ClassDate));
                        this.Hide();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void ButtonAdd_Click(object sender, EventArgs e)
        {
            StudentUserModel student = new StudentUserModel();

            student.FirstName  = textBoxStudentFirstName.Text.Trim();
            student.LastName   = textBoxStudentLastName.Text.Trim();
            student.AcademicId = textBoxStudentId.Text;

            try
            {
                student.IsValid();
                UserController controller = new UserController();
                try
                {
                    BaseUserModel createdStudent = controller.Create(student);

                    SectionStudentController controller1 = new SectionStudentController();
                    controller1.Create(section.Id, createdStudent.Id);

                    ClassController      ccontroller = new ClassController();
                    List <ClassModel>    classList   = ccontroller.GetBySectionId(section.Id);
                    AttendanceController acontroller = new AttendanceController();

                    foreach (ClassModel Class in classList)
                    {
                        AttendanceModel attendance = new AttendanceModel();
                        attendance.StudentId = createdStudent.Id;
                        attendance.ClassId   = Class.Id;
                        try
                        {
                            acontroller.Create(attendance);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }

                    MessageBox.Show(student.FullName + " added in " + section.SectionName);
                    var students = new FormStudentList(faculty, section);
                    students.FormClosed += new FormClosedEventHandler(dash_FormClosed);
                    students.Show();
                    this.Hide();
                }
                catch (NullReferenceException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            catch (SQLiteException ex)
            {
                try
                {
                    UserController controller = new UserController();
                    var            gotStudent = controller.GetByAcademicId(student.AcademicId);
                    string         message    = "Student already exists in our database. Are you sure you want to add " + gotStudent.FullName + "(" + gotStudent.AcademicId + ")?";

                    DialogResult dialogResult = MessageBox.Show(message, "Confirm", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        try
                        {
                            SectionStudentController controller1 = new SectionStudentController();
                            controller1.Create(section.Id, gotStudent.Id);
                            MessageBox.Show(gotStudent.FullName + " added in " + section.SectionName);

                            var students = new FormStudentList(faculty, section);
                            students.FormClosed += new FormClosedEventHandler(dash_FormClosed);
                            students.Show();
                            this.Hide();
                        }
                        catch (SQLiteException exc)
                        {
                            if (exc.ErrorCode == 19)
                            {
                                MessageBox.Show("Error: Student already exists in this section");
                            }
                        }
                        catch (Exception exv)
                        {
                            MessageBox.Show(exv.Message);
                        }
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                        this.Hide();
                    }
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }