コード例 #1
0
        static void Main(string[] args)
        {
            StudentController sc = new StudentController(new SchoolContextDesignFactory().CreateDbContext(args));

            sc.AddStudent("Student 1");
            sc.AddStudent("Student 2");

            foreach (Student s in sc.GetAllStudents())
            {
                Console.WriteLine(s.Id + " - " + s.Name);
            }

            Console.ReadLine();
        }
コード例 #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         byte roomType = new byte();
         if (cbRoomType.SelectedItem.ToString().Split()[0] == "Двойка")
         {
             roomType = 1;
         }
         if (cbRoomType.SelectedItem.ToString().Split()[0] == "Тройка")
         {
             roomType = 0;
         }
         studentController.AddStudent(new Student
         {
             Envicted    = 0,
             Inhabited   = 0,
             GroupName   = cbGroup.SelectedItem.ToString(),
             GroupNumber = int.Parse(txtNumberGroup.Text),
             Room        = cbStage.SelectedItem.ToString() + "-" + cbRoom.SelectedItem.ToString().Split()[0],
             StudentName = txtStudentName.Text,
             RoomType    = roomType
         });
     }
     catch (Exception ex)
     {
         Log.WriteLog(ex.Message);
     }
     this.Close();
 }
コード例 #3
0
        public void ReserveSeat()
        {
            var testClass         = GetTestClass();
            var testStudent       = GetTestStudents();
            var seatController    = new SeatController(_seatLogger);
            var studentController = new StudentController(_studentLogger);
            var classController   = new ClassController(_classLogger);

            DatabaseConnector.Connector.RemoveClass(testClass[0].className);

            // add student
            studentController.RemoveStudent(testStudent);
            var request2 = studentController.AddStudent(testStudent);

            Assert.True(request2[0].response);

            // add class
            var request = classController.MakeClassAPI(testClass);

            Assert.True(request[0].response);

            // reserve a seat
            request = seatController.ReserveSeatAPI(testClass);
            Assert.True(request[0].response);

            // attempt to reserve same seat
            request = seatController.ReserveSeatAPI(testClass);
            Assert.False(request[0].response);

            // cleanup
            studentController.RemoveStudent(testStudent);
            request = classController.RemoveClassAPI(testClass);
        }
コード例 #4
0
ファイル: EditorForm.cs プロジェクト: IWWAYBELTT/projt
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                StudentController Students = new StudentController(_studentService);
                Student           student  = new Student();

                student.FirstName        = txtNom.Text;
                student.LastName         = txtPrenom.Text;
                student.EnrollmentNumber = txtNumInsc.Text;
                student.Email            = txtMail.Text;
                student.IPAddress        = "exp";
                student.ModifiedDate     = DateTime.UtcNow;
                student.depID            = Convert.ToInt32(comboBox1.SelectedValue);


                /*if (Adding)
                 * {*/
                student.AddedDate = DateTime.UtcNow;
                Students.AddStudent(student);
                MessageBox.Show("register succes");

                //}
                //else
                //{
                //    //Students.UpdateStudent(student);
                //    Students.UpdateStudent(student);
                //}
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #5
0
 private void bntInsert_Click(object sender, EventArgs e)
 {
     if (txtName.Text == string.Empty || txtAddress.Text == string.Empty || txtPhone.Text == string.Empty)
     {
         MessageBox.Show("Vui lòng nhập đầy đủ thông tin", "Thông báo");
     }
     else
     {
         decimal?sex;
         if (radioNam.Checked)
         {
             sex = 1;
         }
         else
         {
             sex = 0;
         }
         STUDENT student = new STUDENT();
         student.NAME     = txtName.Text;
         student.ADDRESS  = txtAddress.Text;
         student.PHONE    = txtPhone.Text;
         student.SEX      = sex;
         student.BIRTHDAY = dateTimeBirthday.Value;
         StudentController studentController = new StudentController();
         bool isInsert = studentController.AddStudent(student, cmbYear.SelectedValue.ToString(), cmbClass.Text);
         if (isInsert)
         {
             MessageBox.Show("Nhập thành công", "Thông báo");
         }
         else
         {
             MessageBox.Show("Nhập thất bại, vui lòng thử lại sau", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
コード例 #6
0
 private void buttonAdd_Click(object sender, EventArgs e)
 {
     try
     {
         Student s = new Student();
         s.name            = textBoxName.Text;
         s.roll            = textBoxRoll.Text;
         s.fatherName      = textBoxFathersName.Text;
         s.motherName      = textBoxMothersName.Text;
         s.dateOfBirth     = Convert.ToDateTime(textBoxDateOfBirth.Text);
         s.dateOfAdmission = Convert.ToDateTime(textBoxDateOfAdmission.Text);
         s.contact         = textBoxContact.Text;
         s.address         = richTextBoxAddress.Text;
         s.gender          = comboBoxGender.Text;
         s.userName        = textBoxUserName.Text;
         s.password        = textBoxPassword.Text;
         s.secId           = Int32.Parse(comboBoxSecId.Text);
         s.cId             = Int32.Parse(comboBoxClassId.Text);
         bool b = StudentController.AddStudent(s);
         if (b)
         {
             MessageBox.Show("Student Added");
             this.Close();
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Invalid Input");
     }
 }
コード例 #7
0
        private void btnAddStudent_Click(object sender, EventArgs e)
        {
            frmAdd_Edit  frmadd = new frmAdd_Edit();
            DialogResult rs     = frmadd.ShowDialog();

            if (frmadd.student.MSSV == null)
            {
                return;
            }

            // Mỗi lần Add là mỗi lần load cả List , có nên không nhỉ ???
            ListViewItem St = new ListViewItem(STT.ToString());

            St.SubItems.Add(new ListViewItem.ListViewSubItem(St, frmadd.student.MSSV.ToString()));
            St.SubItems.Add(new ListViewItem.ListViewSubItem(St, frmadd.student.name.ToString()));
            St.SubItems.Add(new ListViewItem.ListViewSubItem(St, frmadd.student.gender.ToString()));
            St.SubItems.Add(new ListViewItem.ListViewSubItem(St, frmadd.student.birthday.ToShortDateString()));
            St.SubItems.Add(new ListViewItem.ListViewSubItem(St, frmadd.student.address.ToString()));
            St.SubItems.Add(new ListViewItem.ListViewSubItem(St, frmadd.student.numberPhone.ToString()));
            St.SubItems.Add(new ListViewItem.ListViewSubItem(St, frmadd.student.faculty.ToString()));
            St.SubItems.Add(new ListViewItem.ListViewSubItem(St, frmadd.student.major.ToString()));
            St.SubItems.Add(new ListViewItem.ListViewSubItem(St, frmadd.student.Class.ToString()));
            St.SubItems.Add(new ListViewItem.ListViewSubItem(St, frmadd.student.course.ToString()));

            this.lstStudent.Items.Add(St);
            StudentController.AddStudent(frmadd.student);
            STT++;
        }
コード例 #8
0
        public void AddAndGetSeat()
        {
            var testStudent       = GetTestStudents();
            var seatController    = new SeatController(_seatLogger);
            var studentController = new StudentController(_studentLogger);
            var classController   = new ClassController(_classLogger);

            // attempt to get seat
            var request = seatController.GetSeatAPI(testStudent);

            Assert.False(request[0].response);

            // add student
            studentController.RemoveStudent(testStudent);
            request = studentController.AddStudent(testStudent);
            Assert.True(request[0].response);

            // add class for student
            request = studentController.AddClass(testStudent);
            Assert.True(request[0].response);

            // add seat
            request = seatController.AddSeatAPI(testStudent);
            Assert.True(request[0].response);

            // get seat
            request = seatController.GetSeatAPI(testStudent);
            Assert.True(request[0].response);

            // cleanup
            request = studentController.RemoveStudent(testStudent);
            Assert.True(request[0].response);
        }
コード例 #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                bool isvalidated = validatefields();
                if (isvalidated)
                {
                    Students students = new Students();
                    students.acadamicYearSem = txtacadamicYearSem.Text;
                    students.programme       = comboprogramme.SelectedItem.ToString();
                    students.groupNo         = Convert.ToInt32(numericUpDowngroupNo.Value);
                    students.subGroupNo      = Convert.ToInt32(numericUpDownsubGroupNo.Value);
                    students.groupId         = txtgroupId.Text;
                    students.subGroupId      = txtsubGroupId.Text;


                    string message = StudentController.AddStudent(students);
                    MessageBox.Show(message);
                    clear();
                }
                else
                {
                    MessageBox.Show("please fill in all fields!");
                }
            }
            catch (NullReferenceException nre)
            {
                MessageBox.Show("please fill in all fields!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #10
0
        public bool EnrollStudent(Student AcceptedStudent)
        {
            bool Confirmation;
            StudentController StudentManager = new StudentController();

            Confirmation = StudentManager.AddStudent(AcceptedStudent);
            return(Confirmation);
        }
コード例 #11
0
 public void TestAddStudent()
 {
     TestStudentController = new StudentController("E:/NAU/TEST/data.dat");
     for (var i = 0; i < 100; i++)
     {
         TestStudentController.AddStudent(new Student(i));
     }
     try
     {
         TestStudentController.AddStudent(new Student(99));
         Assert.Fail();
     }
     catch (Exception e)
     {
         Assert.AreEqual("Student with 99 id, is already exist!", e.Message);
     }
     Assert.AreEqual(new Student(5).Id, TestStudentController.GetStudent(5).Id);
 }
コード例 #12
0
        public void AddStudent()
        {
            var testStudents = GetTestStudents();
            var controller   = new StudentController(_studentLogger);

            DatabaseConnector.Connector.RemoveStudent(testStudents[0].email);
            var request = controller.AddStudent(testStudents);

            Assert.True(request[0].response);
        }
コード例 #13
0
        public override Task <Empty> AddStudent(StudentReply request, ServerCallContext context)
        {
            Student student = new Student
            {
                StudentID   = request.StudentID,
                StudentName = request.Name
            };

            logic.AddStudent(student);
            return(Task.FromResult(new Empty()));
        }
コード例 #14
0
        public void TestInit()
        {
            TestStudentController = new StudentController("E:/NAU/TEST/data.dat");
            Assert.IsInstanceOfType(TestStudentController, typeof(StudentController));

            Repository <Student> tRepo = new Repository <Student>();
            StudentController    tCtrl = new StudentController(tRepo);

            tCtrl.AddStudent(new Student(14));
            Assert.AreEqual(14, tRepo[0].Id);
        }
コード例 #15
0
        public void TestGetStudent()
        {
            TestStudentController = new StudentController("E:/NAU/TEST/data.dat");

            for (var i = 0; i < 50; i++)
            {
                TestStudentController.AddStudent(new Student(i));
            }

            Assert.AreEqual(10, TestStudentController.GetStudent(10).Id);
            Assert.AreEqual(15, TestStudentController.GetStudent(15).Id);
            Assert.AreEqual(23, TestStudentController.GetStudent(23).Id);
        }
コード例 #16
0
        public void AddAndLoginStudent()
        {
            var testStudents      = GetTestStudents();
            var studentController = new StudentController(_studentLogger);

            // add prof
            var request = studentController.AddStudent(testStudents);

            Assert.True(request[0].response);

            // add prof again and fail
            request = studentController.AddStudent(testStudents);
            Assert.False(request[0].response);

            // login prof
            request = studentController.LoginStudent(testStudents);
            Assert.True(request[0].response);

            // cleanup
            request = studentController.RemoveStudent(testStudents);
            Assert.True(request[0].response);
        }
コード例 #17
0
        private void button1_Click(object sender, EventArgs e)
        {
            string name                = txtName.Text;
            string address             = txtAddress.Text;
            string gender              = txtGender.Text;
            string DOB                 = txtDOB.Text;
            string contactNumber       = txtContactNumber.Text;
            string bloodGroup          = txtBloodGroup.Text;
            string fatherName          = txtFatherName.Text;
            string motherName          = txtMotherName.Text;
            string parentContactNumber = txtPContactNumber.Text;
            string course              = txtCourse.Text;
            string block               = txtBlock.Text;
            string status              = txtStatus.Text;

            Student student = new Student();

            student.setName(name);
            student.setAddress(address);
            student.setGender(gender);
            student.setDOB(DOB);
            student.setContactNumber(contactNumber);
            student.setBloodGroup(bloodGroup);
            student.setFatherName(fatherName);
            student.setMotherName(motherName);
            student.setPContactNumber(parentContactNumber);
            student.setCourse(course);
            student.setBlock(block);
            student.setStatus(status);

            StudentController studentController = new StudentController();
            bool result = studentController.AddStudent(student);

            if (result == true)
            {
                MessageBox.Show("Student added successfully");

                txtName.Text           = "";
                txtAddress.Text        = "";
                txtGender.Text         = "";
                txtDOB.Text            = "";
                txtContactNumber.Text  = "";
                txtBloodGroup.Text     = "";
                txtFatherName.Text     = "";
                txtMotherName.Text     = "";
                txtPContactNumber.Text = "";
                txtCourse.Text         = "";
                txtBlock.Text          = "";
                txtStatus.Text         = "";
            }
        }
コード例 #18
0
        public void TestDeleteStudent()
        {
            TestStudentController = new StudentController("E:/NAU/TEST/data.dat");
            for (var i = 0; i < 50; i++)
            {
                TestStudentController.AddStudent(new Student(i));
            }

            for (var i = 0; i < 50; i += 5)
            {
                TestStudentController.RemoveStudent(TestStudentController.GetStudent(i));
            }

            Assert.AreEqual(40, TestStudentController.GetAll().Count);
        }
コード例 #19
0
        private void addstdnBtn_Click(object sender, EventArgs e)
        {
            string name     = nametextBox.Text;
            string sid      = sidtextBox.Text;
            string password = pwdtextBox.Text;
            bool   x        = StudentController.AddStudent(name, sid, password);

            if (x)
            {
                MessageBox.Show("Added");
            }
            else
            {
                MessageBox.Show("Not Added");
            }
        }
コード例 #20
0
        public void PostAddNotValidTestStudent()
        {
            // Arrange
            var mock       = new Mock <IStudentManager>();
            var controller = new StudentController(mock.Object);

            controller.ModelState.AddModelError("Name", "Required");
            var student = new Student {
                DateOfBirth = new DateTime(1980, 10, 5), Email = "*****@*****.**"
            };

            // Act
            var result = controller.AddStudent(student);

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }
コード例 #21
0
        public void AddClass()
        {
            var testStudents      = GetTestStudents();
            var studentController = new StudentController(_studentLogger);

            DatabaseConnector.Connector.RemoveStudent(testStudents[0].email);
            var request = studentController.AddStudent(testStudents);

            if (request[0].response)
            {
                var request2 = studentController.AddClass(testStudents);
                Assert.True(request2[0].response);
            }

            // cleanup
            studentController.RemoveStudent(testStudents);
        }
コード例 #22
0
        public void PostAddTestStudent()
        {
            // Arrange
            var mock       = new Mock <IStudentManager>();
            var controller = new StudentController(mock.Object);
            var student    = new Student {
                Id = 1, Name = "Tom", DateOfBirth = new DateTime(1980, 10, 5), Email = "*****@*****.**"
            };

            // Act
            var result = controller.AddStudent(student);

            // Assert
            var okObjectResult = Assert.IsType <OkObjectResult>(result);

            Assert.Equal(student, okObjectResult?.Value);
        }
コード例 #23
0
ファイル: FrmMain.cs プロジェクト: touna23/CrudRepNUnit
        private void AddNewStudent_Click(object sender, EventArgs e)
        {
            int studentId = Convert.ToInt32(labelStudentId.Text);
            StudentController Students = new StudentController(_studentService);

            if (studentId == 0)
            {
                try
                {
                    Student student = new Student
                    {
                        FirstName        = Txt_StudentName.Text,
                        LastName         = txtPrenom.Text,
                        EnrollmentNumber = txtNumInsc.Text,
                        Email            = txtMail.Text,
                        IPAddress        = "exp",
                        ModifiedDate     = DateTime.UtcNow,
                        DeptId           = Convert.ToInt32(comboDept.SelectedValue)
                    };
                    student.AddedDate = DateTime.UtcNow;
                    Students.AddStudent(student);
                }
                catch (FoException ex)
                {
                    throw ex;
                }
            }
            else
            {
                var studToUpdate = Students.GetByIdStudent(studentId);
                if (studToUpdate != null)
                {
                    studToUpdate.FirstName        = Txt_StudentName.Text;
                    studToUpdate.LastName         = txtPrenom.Text;
                    studToUpdate.EnrollmentNumber = txtNumInsc.Text;
                    studToUpdate.Email            = txtMail.Text;
                    studToUpdate.ModifiedDate     = DateTime.UtcNow;
                    studToUpdate.DeptId           = Convert.ToInt32(comboDept.SelectedValue);
                }
                Students.UpdateStudent(studToUpdate);
            }
            MessageBox.Show(this, "Employee Saved Successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);

            LoadStudents();
        }
コード例 #24
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtMSSV.Text.Trim().Length <= 0)
            {
                erpAdd.SetError(txtMSSV, "Không được để trống trường MSSV!");
                return;
            }
            if (txtHoTen.Text.Trim().Length <= 0)
            {
                erpAdd.SetError(txtHoTen, "Không được để trống họ tên!");
                return;
            }
            if (DateTime.Now.Year - dtpNgaySinh.Value.Year < 18)
            {
                erpAdd.SetError(dtpNgaySinh, "Yêu cầu phải đủ 18 tuổi trở lên!");
                return;
            }
            if (cmbChuyenNganh.Text.Trim().Length <= 0)
            {
                erpAdd.SetError(cmbChuyenNganh, "Không được để trống chuyên ngành!");
                return;
            }
            erpAdd.Clear();
            SinhVien student = new SinhVien();

            student.Mssv          = txtMSSV.Text;
            student.HoTen         = txtHoTen.Text;
            student.GioiTinh      = cmbGioiTinh.SelectedItem.ToString();
            student.NgaySinh      = dtpNgaySinh.Value;
            student.QueQuan       = txtQueQuan.Text;
            student.IDChuyenNganh = cmbChuyenNganh.Text;
            student.NamNhapHoc    = txtNamNhapHoc.Text;
            student.DaXoa         = false;
            if (StudentController.AddStudent(student) is false)
            {
                MessageBox.Show("Không thể thêm sinh viên!", "Cảnh báo!", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }
            txtMSSV.Clear();
            txtHoTen.Clear();
            cmbGioiTinh.Text = cmbGioiTinh.Items[0].ToString();
            dtpNgaySinh.ResetText();
            txtQueQuan.Clear();
            txtNamNhapHoc.Clear();
            this.Close();
        }
コード例 #25
0
        public void TestGetAll()
        {
            TestStudentController = new StudentController("E:/NAU/TEST/data.dat");

            for (var i = 0; i < 50; i++)
            {
                TestStudentController.AddStudent(new Student(i));
            }

            var listOfStudents = TestStudentController.GetAll();
            int tId            = 0;

            foreach (var item in listOfStudents)
            {
                Assert.AreEqual(tId, item.Id);
                tId++;
            }
        }
コード例 #26
0
        public void TestChangeStudent()
        {
            TestStudentController = new StudentController("E:/NAU/TEST/data.dat");
            for (var i = 0; i < 50; i++)
            {
                TestStudentController.AddStudent(new Student(i));
            }

            TestStudentController.ChangeStudent(
                TestStudentController.GetStudent(43),
                new Student(90));

            TestStudentController.ChangeStudent(
                TestStudentController.GetStudent(42),
                new Student(80));

            Assert.AreEqual(90, TestStudentController.GetStudent(90).Id);
            Assert.AreEqual(80, TestStudentController.GetStudent(80).Id);
        }
コード例 #27
0
        private void addstdnBtn_Click(object sender, EventArgs e)
        {
            string name     = nametextBox.Text;
            string sid      = sidtextBox.Text;
            string password = pwdtextBox.Text;
            bool   x        = StudentController.AddStudent(name, sid, password);

            if (x)
            {
                MessageBox.Show("Student Added");
                this.tc = this.tc + 1;
                string stc = this.tc.ToString();
                countTextBox.Text = stc;
            }
            else
            {
                MessageBox.Show("Student Not Added");
            }
        }
コード例 #28
0
        public async void AddStudent_Return_BadRequest_ModalValidationn()
        {
            // Arrange
            var controller = new StudentController(_logger_1.Object, _logger.Object, _studentService.Object, _httpContextAccessor.Object, _baseAuth.Object);
            CancellationToken ct;

            controller.ModelState.AddModelError("fakeError", "fakeError");
            Student stud = new Student()
            {
                ID = 3, Address = "Chennai", Email = "ram@", Role = "Stud"
            };

            _studentService.Setup(x => x.AddStudent(stud, ct)).Returns(Task.FromResult(stud));

            // Act
            var response = await controller.AddStudent(stud, ct);

            // Assert
            //Assert.Null(response);
            Assert.IsType <BadRequestObjectResult>(response);
        }
コード例 #29
0
        public void RemoveClassFromStudent()
        {
            var testClass         = GetTestClass();
            var testStudent       = GetTestStudents();
            var studentController = new StudentController(_studentLogger);
            var classController   = new ClassController(_classLogger);

            // add student
            DatabaseConnector.Connector.RemoveStudent(testStudent[0].email);
            var request = studentController.AddStudent(testStudent);

            Assert.True(request[0].response);

            // make class
            DatabaseConnector.Connector.RemoveClass(testClass[0].className);
            var request2 = classController.MakeClassAPI(testClass);

            Assert.True(request2[0].response);

            //add class
            request = studentController.AddClass(testStudent);
            Assert.True(request[0].response);

            // get student, assert class attached to student
            request = studentController.GetStudentAPI(testStudent);
            Assert.True(request[0].classes.Length == 1);

            // remove class from student
            request = studentController.RemoveClassFromStudent(testStudent);
            Assert.True(request[0].response);

            // get student
            request = studentController.GetStudentAPI(testStudent);
            //Assert.True(request[0].classes.Length == 0);

            // cleanup
            classController.RemoveClassAPI(testClass);
            request = studentController.RemoveStudent(testStudent);
            Assert.True(request[0].response);
        }
コード例 #30
0
        public void GetStudent()
        {
            var testStudent = GetTestStudents();
            var controller  = new StudentController(_studentLogger);

            // attempt to get student
            controller.RemoveStudent(testStudent);
            var request = controller.GetStudentAPI(testStudent);

            Assert.False(request[0].response);

            // add student
            request = controller.AddStudent(testStudent);
            Assert.True(request[0].response);

            // get student
            request = controller.GetStudentAPI(testStudent);
            Assert.True(request[0].response);

            // cleanup
            request = controller.RemoveStudent(testStudent);
            Assert.True(request[0].response);
        }