public void Delete_ExistingStudent_OkResult() { var controller = new StudentController(_logger, _studentService); var student = new Entities.Models.Student { Id = new Guid("f7afefa9-2cc6-4ea9-901d-d99e227a12de"), FirstName = "Bart", LastName = "Simpson", DocumentType = Entities.Models.EDocumentType.CC, DocumentNumber = "97654315", Address = "Springfield 123", Email = "*****@*****.**", City = "Springfield", PhoneNumber = "7654321", Birth = new DateTime(1950, 11, 1) }; var data = controller.CreateStudent(student); Assert.IsType <CreatedAtRouteResult>(data as CreatedAtRouteResult); var deleteResult = controller.DeleteStudent(student.Id); Assert.IsType <NoContentResult>(deleteResult); }
private void button3_Click(object sender, EventArgs e) { string id = txtStudentId.Text; StudentController studentController = new StudentController(); bool i = studentController.DeleteStudent(id); if (i == true) { MessageBox.Show("Student Information deleted succesfully!"); txtStudentId.Text = ""; txtName.Text = ""; txtAddress.Text = ""; txtGender.Text = ""; txtDOB.Text = ""; txtContactNumber.Text = ""; txtBloodGroup.Text = ""; txtFatherName.Text = ""; txtMotherName.Text = ""; txtPContactNumber.Text = ""; txtCourse.Text = ""; txtBlock.Text = ""; txtStatus.Text = ""; } else { MessageBox.Show("Student Information not deleted "); } }
private void btnDelete_Click(object sender, EventArgs e) { string id = ""; try { id = txtID.Text; } catch { } DialogResult dr = MessageBox.Show("Bạn có chắc chắn xóa ?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { int i = 0; i = StudentController.DeleteStudent(id); if (i > 0) { MessageBox.Show(" Xóa thành công"); DisplayStudent(); ClearData(); Student_Load(sender, e); } else { MessageBox.Show("Xóa không thành công"); } } else { return; } }
public bool RemoveStudent(string StudentId) { bool Success; StudentController StudentManager = new StudentController(); Success = StudentManager.DeleteStudent(StudentId); return(Success); }
public void Delete_NonExistingStudent_NotFoundResult() { var controller = new StudentController(_logger, _studentService); var studentId = new Guid("1c575a69-27f3-4379-b7be-5798a0001449"); var data = controller.DeleteStudent(studentId); Assert.IsType <NotFoundResult>(data); }
private void dgStudent_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { StudentAddForm studentAddForm = new StudentAddForm(); studentAddForm.ShowDialog(); StudentForm_Load(sender, e); } if (e.KeyCode == Keys.Delete && dgStudent.SelectedRows.Count == 1) { DialogResult dialogResult = MessageBox.Show("Потвердите удаление.", "Подтверждение", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { studentController.DeleteStudent(int.Parse(dgStudent[0, dgStudent.SelectedRows[0].Index].Value.ToString())); StudentForm_Load(sender, e); } } }
private void btnDelete_Click(object sender, EventArgs e) { string id = dtgThongTinSinhVien.CurrentRow.Cells[0].Value.ToString(); if (StudentController.DeleteStudent(id) == false) { MessageBox.Show("Sinh viên không tồn tại!", "Lỗi", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } dtgThongTinSinhVien.AutoGenerateColumns = false; dtgThongTinSinhVien.DataSource = StudentController.GetListStudent(); }
private void DeleteStudent(StudentDto studentDto) { var response = _controller.DeleteStudent(studentDto); var lista = (List <string>)response; foreach (var bad in lista) { Console.WriteLine($"{bad}"); } UserInteraction.PressToBackToMenu(); }
public async void Task_Delete_Return_BadRequestResult() { //Arrange var controller = new StudentController(repository); int?studId = null; //Act var data = await controller.DeleteStudent(studId); //Assert Assert.IsType <BadRequestResult>(data); }
public async void Task_Delete_Student_Return_NotFoundResult() { //Arrange var controller = new StudentController(repository); var studId = 5; //Act var data = await controller.DeleteStudent(studId); //Assert Assert.IsType <NotFoundResult>(data); }
private static void GenerateMenu() { var studentController = new StudentController(); while (true) { Console.Clear(); Console.WriteLine("===================STUDENT MANAGER================"); Console.WriteLine("1. Add Student"); Console.WriteLine("2. Show List Student"); Console.WriteLine("3. Update Student"); Console.WriteLine("4. Delete Student"); Console.WriteLine("5. Exit"); Console.WriteLine("==================================================="); Console.WriteLine("Please enter your choice: "); var choice = int.Parse(Console.ReadLine()); switch (choice) { case 1: studentController.CreateStudent(); break; case 2: studentController.ShowList(); break; case 3: studentController.UpdateStudent(); break; case 4: studentController.DeleteStudent(); break; case 5: Console.WriteLine("Close application!"); break; default: Console.WriteLine("Please choice from 1 to 5!"); break; } if (choice == 5) { Console.WriteLine("See you again!"); break; } Console.WriteLine("Press any key to continue!"); Console.Read(); } }
private void dltstndBtnClk(object sender, EventArgs e) { string name = richTextBox1.Text; bool x = StudentController.DeleteStudent(name); if (x) { MessageBox.Show("Student Deleted !"); } else { MessageBox.Show("Student Not Deleted"); } }
private void buttonDelete_Click(object sender, EventArgs e) { int sId = Int32.Parse(textBoxSearch.Text); bool b = StudentController.DeleteStudent(sId); if (b) { MessageBox.Show("Deleted"); this.Close(); } else { MessageBox.Show("Fail to delete"); } }
// ToDo: Figure out why the mock setup for SchoolRepository.DeleteSchool() is not being mocked correctly //[TestMethod] public void DeleteStudent() { // Arrange var student = DataSeeder.StudentSeeder.Objects.FirstOrDefault(); Assert.IsTrue(student != null, "No students setup in the data seeder"); Mock.Get(_repositoryWrapper.Student).Setup(x => x.DeleteStudent(student)); Mock.Get(_repositoryWrapper.Student).Setup(x => x.GetStudentById(student.Id)).ReturnsAsync(student); Mock.Get(_repositoryWrapper.SchoolStudent).Setup(x => x.SchoolStudentsByStudent(student.Id)).ReturnsAsync(new List <SchoolStudent>()); var controller = new StudentController(_loggerManager, _mapper, _repositoryWrapper); // Act var actionResult = controller.DeleteStudent(student.Id).Result; // Assert var noContentResult = actionResult as NoContentResult; Assert.IsNotNull(noContentResult); }
private void btnDelete_Click(object sender, EventArgs e) { try { controller.DeleteStudent(dgvDeleteStudent); MessageBox.Show("System successfully deleted student"); } catch (ArgumentOutOfRangeException) { MessageBox.Show("You must select entire row to delete student"); return; } catch (DeleteException ex) { MessageBox.Show("System cannot delete student"); MessageBox.Show(ex.Message); return; } }
private void btnDelete_Click(object sender, EventArgs e) { if (this.dgvStudent.SelectedRows.Count <= 0) { return; } string idstudent = this.dgvStudent.SelectedRows[0].Cells[0].Value.ToString().Trim(); if (StudentController.DeleteStudent(idstudent) == false) { MessageBox.Show("Cannot delete student!!!"); } else { MessageBox.Show("Delete success!!!", "Note", MessageBoxButtons.OK); BindingSource source = new BindingSource(); source.DataSource = StudentController.getAllStudent(); this.dgvStudent.DataSource = source; } }
public void DeleteTestStudent() { // Arrange int testStudentId = 1; var mock = new Mock <IStudentManager>(); var controller = new StudentController(mock.Object); mock.Setup(manager => manager.DeleteStudent(testStudentId)) .Returns(GetTestStudents().FirstOrDefault(s => s.Id == testStudentId)); // Act var result = controller.DeleteStudent(testStudentId); // Assert var okObjectResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsType <Student>(okObjectResult?.Value); Assert.Equal(1, model.Id); Assert.Equal("Tom", model.Name); Assert.Equal(new DateTime(1980, 10, 5), model.DateOfBirth); Assert.Equal("*****@*****.**", model.Email); }
static void Main(string[] args) { StudentController controller = new StudentController(); bool running = true; while (running) { Console.WriteLine("Enter your choice of operation\n--------------------------------------\n" + "1.Create Student\n" + "2.Update Student\n" + "3.Delete Student\n" + "4.List all students\n" + "5.Exit\n------------------------------------\n"); int choice = Convert.ToInt32(Console.ReadLine()); switch (choice) { case 1: Student s = new Student(); Console.WriteLine("Enter student information\n-------------------------------------------\n"); Console.WriteLine("Enter student id\t"); s.StudentId = Console.ReadLine(); Console.WriteLine("Enter the students firstname"); s.firstName = Console.ReadLine(); Console.WriteLine("Enter students last name"); s.lastname = Console.ReadLine(); Console.WriteLine("Enter student Email"); s.email = Console.ReadLine(); controller.CreateStudent(s); break; case 2: Student n = new Student(); Console.WriteLine("Enter new student information\n-------------------------------------------\n"); Console.WriteLine("Enter id of student to be updated\t"); n.StudentId = Console.ReadLine(); Console.WriteLine("Enter the students new firstname\t"); n.firstName = Console.ReadLine(); Console.WriteLine("Enter students new last name\t"); n.lastname = Console.ReadLine(); Console.WriteLine("Enter students new Email\t"); n.email = Console.ReadLine(); controller.UpdateStudent(n); break; case 3: Console.WriteLine("Enter student id o fstudent to be deleted\t"); string studentIdtoBeDeleted = Console.ReadLine(); controller.DeleteStudent(studentIdtoBeDeleted); break; case 4: List <Student> students = new List <Student>(); students = controller.ListStudents(); Console.WriteLine("StudentId\t\t\t\tFirstname\t\t\t\tLastName\t\t\t\t\tEmail\n-----------------\t\t\t-----------------\t\t\t-----------------\t\t\t-----------------\n"); foreach (Student a in students) { Console.WriteLine(a.StudentId + "\t\t\t\t\t" + a.firstName + "\t\t\t\t\t" + a.lastname + "\t\t\t\t\t" + a.email); } break; case 5: running = false; break; default: Console.WriteLine("Invalid Input choice"); break; } } }
public async Task DeleteStudent() { var options = new DbContextOptionsBuilder <BackendTestDbContext>() .UseInMemoryDatabase(databaseName: "UpdateStudentDatabase") .Options; var savedMasterClass = new ClassMaster(); var savedDetailClass = new ClassDetail(); #region SaveMasterClass using (var context = new BackendTestDbContext(options)) { var classMasterRepository = new ClassMasterRepository(context); var classDetailRepository = new ClassDetailRepository(context); var studentRepository = new StudentRepository(context); var classDetailStudentRepository = new ClassDetailStudentRepository(context); var classController = new ClassController(classMasterRepository, classDetailRepository, studentRepository, classDetailStudentRepository); var toBeSavedEntity = new ClassMasterDto { Classname = "Computer Engineering", Location = "Some where", TeacherName = "Dr. Demberg" }; var rawJson = await classController.SaveMasterClass(toBeSavedEntity); var res = (WebApiSimpleResponse <ClassMaster>)rawJson.Value; savedMasterClass = res.Result; Assert.IsFalse(res.ErrorFlag); } #endregion #region SaveDetailClass using (var context = new BackendTestDbContext(options)) { var classMasterRepository = new ClassMasterRepository(context); var classDetailRepository = new ClassDetailRepository(context); var studentRepository = new StudentRepository(context); var classDetailStudentRepository = new ClassDetailStudentRepository(context); var classController = new ClassController(classMasterRepository, classDetailRepository, studentRepository, classDetailStudentRepository); var toBeSavedEntity = new ClassDetailDto { ClassMasterId = savedMasterClass.Id }; var rawJson = await classController.SaveDetailClass(toBeSavedEntity); var res = (WebApiSimpleResponse <ClassDetail>)rawJson.Value; savedDetailClass = res.Result; Assert.IsFalse(res.ErrorFlag); } #endregion var student = new Student(); #region SaveStudent using (var context = new BackendTestDbContext(options)) { var _studentRepository = new StudentRepository(context); var _classDetailStudentRepository = new ClassDetailStudentRepository(context); var studentController = new StudentController(_studentRepository, _classDetailStudentRepository); var toBeSavedStudent = new StudentDto { FirstName = "John", LastName = "Smith", Gpa = (decimal)15.2, Age = 20 }; var rawJsonRes1 = await studentController.SaveStudent(toBeSavedStudent); student = ((WebApiSimpleResponse <Student>)rawJsonRes1.Value).Result; Assert.IsFalse(((WebApiSimpleResponse <Student>)rawJsonRes1.Value).ErrorFlag); } #endregion #region AddStudentToDetailClass using (var context = new BackendTestDbContext(options)) { var classMasterRepository = new ClassMasterRepository(context); var classDetailRepository = new ClassDetailRepository(context); var studentRepository = new StudentRepository(context); var classDetailStudentRepository = new ClassDetailStudentRepository(context); var classController = new ClassController(classMasterRepository, classDetailRepository, studentRepository, classDetailStudentRepository); var toBeSavedEntity = new ClassDetailDto { ClassDetailId = savedDetailClass.Id, StudentDtos = new List <StudentDto> { new StudentDto { Id = student.Id } } }; var rawJson = await classController.AddStudentsToDetailClass(toBeSavedEntity); var res = (WebApiSimpleResponse <ClassDetailStudent>)rawJson.Value; Assert.IsFalse(res.ErrorFlag); } #endregion #region DeleteWithNullValue using (var context = new BackendTestDbContext(options)) { var _studentRepository = new StudentRepository(context); var _classDetailStudentRepository = new ClassDetailStudentRepository(context); var studentController = new StudentController(_studentRepository, _classDetailStudentRepository); var rawJsonDelete = await studentController.DeleteStudent(null); var deleteStudentRes = (WebApiSimpleResponse <Student>)rawJsonDelete.Value; Assert.IsTrue(deleteStudentRes.ErrorFlag); } #endregion #region DeleteAStudentEnrolledInAClass using (var context = new BackendTestDbContext(options)) { var _studentRepository = new StudentRepository(context); var _classDetailStudentRepository = new ClassDetailStudentRepository(context); var studentController = new StudentController(_studentRepository, _classDetailStudentRepository); var toBeDeletedStudent = new StudentDto { Id = student.Id, }; var rawJsonDelete = await studentController.DeleteStudent(toBeDeletedStudent); var deleteStudentRes = (WebApiSimpleResponse <Student>)rawJsonDelete.Value; Assert.IsTrue(deleteStudentRes.ErrorFlag); } #endregion #region RemoveStudentFromDetailClass using (var context = new BackendTestDbContext(options)) { var classMasterRepository = new ClassMasterRepository(context); var classDetailRepository = new ClassDetailRepository(context); var studentRepository = new StudentRepository(context); var classDetailStudentRepository = new ClassDetailStudentRepository(context); var classController = new ClassController(classMasterRepository, classDetailRepository, studentRepository, classDetailStudentRepository); var toBeSavedEntity = new ClassDetailDto { ClassDetailId = savedDetailClass.Id, StudentDtos = new List <StudentDto> { new StudentDto { Id = student.Id } } }; var rawJson = await classController.RemoveStudentsFromDetailClass(toBeSavedEntity); var res = (WebApiSimpleResponse <ClassMasterDto>)rawJson.Value; Assert.IsFalse(res.ErrorFlag); } #endregion #region NiceStudentDelete using (var context = new BackendTestDbContext(options)) { var _studentRepository = new StudentRepository(context); var _classDetailStudentRepository = new ClassDetailStudentRepository(context); var studentController = new StudentController(_studentRepository, _classDetailStudentRepository); var toBeDeletedStudent = new StudentDto { Id = student.Id, }; var rawJsonDelete = await studentController.DeleteStudent(toBeDeletedStudent); var deleteStudentRes = (WebApiSimpleResponse <Student>)rawJsonDelete.Value; Assert.IsFalse(deleteStudentRes.ErrorFlag); var rawJsonGetStudentById = studentController.GetStudentById(toBeDeletedStudent.Id); var getStudentByIdRes = (WebApiSimpleResponse <StudentDto>)rawJsonGetStudentById.Value; Assert.IsTrue(getStudentByIdRes.ErrorFlag); } #endregion #region InvalidId using (var context = new BackendTestDbContext(options)) { var _studentRepository = new StudentRepository(context); var _classDetailStudentRepository = new ClassDetailStudentRepository(context); var studentController = new StudentController(_studentRepository, _classDetailStudentRepository); var toBeDeletedStudent = new StudentDto { Id = student.Id, }; var rawJsonDelete = await studentController.DeleteStudent(toBeDeletedStudent); var deleteStudentRes = (WebApiSimpleResponse <Student>)rawJsonDelete.Value; Assert.IsTrue(deleteStudentRes.ErrorFlag); } #endregion }
internal void EditStudent() { int studentCount = studentController.StudentCount(); if (studentCount > 0) { Console.WriteLine("Please enter only one student id as displayed below"); DisplayStudent(); Console.Write("> "); var studentIdToChange = Console.ReadLine(); while (studentController.SearchStudent(studentIdToChange) == null) { Console.WriteLine("Sorry! The student you wanna edit does not exist. Try again!"); Console.Write("> "); studentIdToChange = Console.ReadLine(); } Student oldStudent = studentController.SearchStudent(studentIdToChange); Console.Write("You will change old id \"{0}\" to new id or press [Enter] to unchange: ", oldStudent.Id); string updatedId = Console.ReadLine(); Console.Write("You will change old first name \"{0}\" to new name or press [Enter] to unchange: ", oldStudent.FirstName); string updatedFName = Console.ReadLine(); Console.Write("You will change old middle name \"{0}\" to new name or press [Enter] to unchange: ", oldStudent.MiddleName); string updatedMName = Console.ReadLine(); Console.Write("You will change old last name \"{0}\" to new name or press [Enter] to unchange: ", oldStudent.LastName); string updatedLName = Console.ReadLine(); if (updatedId == "") { updatedId = oldStudent.Id; } if (updatedFName == "") { updatedFName = oldStudent.FirstName; } if (updatedMName == "") { updatedMName = oldStudent.MiddleName; } if (updatedLName == "") { updatedLName = oldStudent.LastName; } // Keep old information of student to modify if it happens error during updating string id = oldStudent.Id; string fName = oldStudent.FirstName; string mName = oldStudent.MiddleName; string lName = oldStudent.LastName; // Delete course to edit by its id studentController.DeleteStudent(studentIdToChange); if (studentController.UpdateStudent(updatedId, updatedFName, updatedMName, updatedLName)) { Console.WriteLine("You updated new information for student id: " + updatedId); } else { // Recreate old lecturer if updating fail studentController.CreateStudent(id, fName, mName, lName); Console.WriteLine("You failed to update new information for student id: " + id); Console.WriteLine(); } } else { Console.WriteLine("Opp! empty student list. You should use selection 1 to add a student."); } Console.WriteLine("Press[Enter] button to continue..."); Console.ReadLine(); }