private void addLec_Click(object sender, EventArgs e) { Lecturer lecturer = new Lecturer(); if (eidtxt.Text.Length != 6) { } else { lecturer.lecName = nametxt.Text; lecturer.eid = eidtxt.Text; lecturer.faculty = factxt.Text; lecturer.department = depttxt.Text; lecturer.center = centertxt.Text; lecturer.buildng = buildingtxt.Text; lecturer.level = leveltxt.Text; lecturer.rank = ranktxt.Text; ranktxt.Text = lecturer.level + "." + lecturer.eid; LectureController leccrl = new LectureController(); leccrl.insertLecturerDetails(lecturer); nametxt.Text = ""; eidtxt.Text = ""; factxt.Text = ""; depttxt.Text = ""; centertxt.Text = ""; buildingtxt.Text = ""; leveltxt.Text = ""; ranktxt.Text = ""; lecturerTble.DataSource = leccrl.getdatatoTable(); } }
private void btnAdd_Click(object sender, EventArgs e) { Lecture lecture = new Lecture(); lecture.L_ID = this.txtLectureID.Text.Trim(); lecture.L_name = this.txtLecturename.Text.Trim(); lecture.L_fullname = this.txtFullname.Text.Trim(); lecture.L_department = this.cmbDepartment.Text.Trim(); lecture.L_gender = this.cmbGender.Text.Trim(); lecture.L_birthday = DateTime.Parse(this.dateTimeBirthday.Text.Trim()); lecture.L_email = this.txtEmail.Text.Trim(); lecture.L_phone = this.txtPhone.Text.Trim(); if (LectureController.addLecture(lecture) == false) { MessageBox.Show("Error in adding a new lecture!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } BindingSource source = new BindingSource(); source.DataSource = LectureController.getAllLecture(); this.dgvLecture.DataSource = source; }
private void button1_Click(object sender, EventArgs e) { if (!( txbSpeaker.Text == String.Empty || txbTitle.Text == String.Empty || txbDate.Text == String.Empty || cbHour.SelectedItem == null )) { string title = txbTitle.Text; string day = txbDate.Text; string hour = cbHour.SelectedItem.ToString(); string speaker = txbSpeaker.Text; try { var lect = new Lecture(title, speaker, day, hour); var ctrl = new LectureController(); ctrl.Insert(lect); MessageBox.Show($"Lecture \"{lect.Title}\" was succesfully registered!"); ClearForm(); } catch (Exception ex) { MessageBox.Show($"Failed to insert in table Lecture\n Error:\n{ex.Message}"); } } else { MessageBox.Show("Please fill in the fields properly"); } }
public LecturerForm() { InitializeComponent(); LectureController lectureController = new LectureController(); lecturerTble.DataSource = lectureController.getdatatoTable(); //lecturerTble.DataBindings(); }
public async Task PutLecture_BadRequest() { var response = await LectureController.Put(null); var code = (StatusCodeResult)response.Result; Assert.AreEqual((int)HttpStatusCode.BadRequest, code.StatusCode); }
public async Task PutLecture_ValidCall() { var response = await LectureController.Put(ViewModel().Result); var code = ((ObjectResult)response.Result).StatusCode; Assert.AreEqual((int)HttpStatusCode.OK, code); }
private void btnUpdate_Click(object sender, EventArgs e) { Lecture lecture = new Lecture(); lecture.L_ID = this.dgvLecture.CurrentRow.Cells[0].Value.ToString(); if (lecture.L_ID.Length <= 0) { return; } if (this.dgvLecture.CurrentRow.Cells[1].Value is null) { this.dgvLecture.CurrentRow.Cells[1].Value = ""; } lecture.L_name = this.txtLecturename.Text.Trim(); if (this.dgvLecture.CurrentRow.Cells[2].Value is null) { this.dgvLecture.CurrentRow.Cells[2].Value = ""; } lecture.L_fullname = this.txtFullname.Text.Trim(); if (this.dgvLecture.CurrentRow.Cells[3].Value is null) { this.dgvLecture.CurrentRow.Cells[3].Value = ""; } lecture.L_department = this.cmbDepartment.Text.Trim(); if (this.dgvLecture.CurrentRow.Cells[4].Value is null) { this.dgvLecture.CurrentRow.Cells[4].Value = ""; } lecture.L_gender = this.cmbGender.Text.Trim(); if (this.dgvLecture.CurrentRow.Cells[5].Value is null) { this.dgvLecture.CurrentRow.Cells[5].Value = ""; } lecture.L_birthday = this.dateTimeBirthday.Value; if (this.dgvLecture.CurrentRow.Cells[6].Value is null) { this.dgvLecture.CurrentRow.Cells[6].Value = ""; } lecture.L_phone = this.txtPhone.Text.Trim(); if (this.dgvLecture.CurrentRow.Cells[7].Value is null) { this.dgvLecture.CurrentRow.Cells[7].Value = ""; } lecture.L_email = this.txtEmail.Text.Trim(); if (LectureController.UpdateLecture(lecture) == false) { MessageBox.Show("Cannot update!!!"); } else { MessageBox.Show("Update success", "Note", MessageBoxButtons.OK); BindingSource source = new BindingSource(); source.DataSource = LectureController.getAllLecture(); this.dgvLecture.DataSource = source; } }
public async Task PutLecture_NotFound() { Mock.Setup(service => service.Find(It.IsAny <Func <Lecture, bool> >())) .Returns(PutNotFoundTest()); var response = await LectureController.Put(ViewModel().Result); var code = (StatusCodeResult)response.Result; Assert.AreEqual((int)HttpStatusCode.NotFound, code.StatusCode); }
private void btnEnter_Click(object sender, EventArgs e) { try { string username = this.txtUsername.Text; string pwd = this.txtPassword.Text; if (LoginController.checkUser(username, pwd) == true) { var lectureLogged = radioLecture.Checked; if (lectureLogged) { var lecture = LectureController.getLectureInfomationAfterLogin(username); if (lecture == null) { MessageBox.Show("Login failed ! Please check your information!!!"); txtPassword.Text = ""; return; } using (var frm = new frmMainMDI(lectureLogged, lecture.L_fullname)) { frm.ShowDialog(); this.Hide(); } } else { var student = StudentController.getStudentInfomationAfterLogin(username); if (student == null) { MessageBox.Show("Login failed ! Please check your information!!!"); txtPassword.Text = ""; return; } using (var frm = new frmMainMDI(lectureLogged, student.S_fullname)) { frm.ShowDialog(); this.Hide(); } } } else { MessageBox.Show("Login failed ! Please check your information!!!"); txtPassword.Text = ""; } } catch { } }
public void SetUp() { Mock = new Mock <ILectureService>(); Mock.Setup(service => service.GetAsync(It.IsAny <int>())) .Returns(GetTest()); Mock.Setup(service => service.CreateAsync(It.IsAny <LectureDTO>())) .Returns(ViewModel()); Mock.Setup(service => service.UpdateAsync(It.IsAny <LectureDTO>())) .Returns(ViewModel()); Mock.Setup(service => service.Find(It.IsAny <Func <Lecture, bool> >())) .Returns(PutFindTest()); Mock.Setup(service => service.DeleteAsync(It.IsAny <int>())) .Returns(ViewModel()); LectureController = new LectureController(Mock.Object, new MapperPL()); }
public frmLecture() { InitializeComponent(); this.cID.DataPropertyName = nameof(Lecture.L_ID); this.cLecturename.DataPropertyName = nameof(Lecture.L_name); this.cFullname.DataPropertyName = nameof(Lecture.L_fullname); this.cDepartment.DataPropertyName = nameof(Lecture.L_department); this.cGender.DataPropertyName = nameof(Lecture.L_gender); this.cBirthday.DataPropertyName = nameof(Lecture.L_birthday); this.cPhone.DataPropertyName = nameof(Lecture.L_phone); this.cEmail.DataPropertyName = nameof(Lecture.L_email); this.cmbGender.DataSource = listgender; this.cmbDepartment.DataSource = listdepartment; BindingSource source = new BindingSource(); source.DataSource = LectureController.getAllLecture(); this.dgvLecture.DataSource = source; }
private void btnDelete_Click(object sender, EventArgs e) { if (this.dgvLecture.SelectedRows.Count <= 0) { return; } string idlecture = this.dgvLecture.SelectedRows[0].Cells[0].Value.ToString().Trim(); if (LectureController.DeleteLecture(idlecture) == false) { MessageBox.Show("Cannot delete lecture!!!"); } else { MessageBox.Show("Delete success!!!", "Note", MessageBoxButtons.OK); BindingSource source = new BindingSource(); source.DataSource = LectureController.getAllLecture(); this.dgvLecture.DataSource = source; } }
private void editLec_Click(object sender, EventArgs e) { Lecturer lecturer = new Lecturer(); lecturer.lecName = nametxt.Text; lecturer.eid = eidtxt.Text; lecturer.faculty = factxt.Text; lecturer.department = depttxt.Text; lecturer.center = centertxt.Text; lecturer.buildng = buildingtxt.Text; lecturer.level = leveltxt.Text; lecturer.rank = ranktxt.Text; ranktxt.Text = lecturer.level + "." + lecturer.eid; LectureController ctrl = new LectureController(); ctrl.UpdateLecturer(lecturer); lecturerTble.DataSource = ctrl.getdatatoTable(); }
private void editLec_Click(object sender, EventArgs e) { if (nametxt.Text != "" && eidtxt.Text != "" && factxt.Text != "" && depttxt.Text != "" && centertxt.Text != "" && buildingtxt.Text != "" && leveltxt.Text != "" && ranktxt.Text != "") { Lecturer lecturer = new Lecturer(); lecturer.lecName = nametxt.Text; lecturer.eid = eidtxt.Text; lecturer.faculty = factxt.Text; lecturer.department = depttxt.Text; lecturer.center = centertxt.Text; lecturer.buildng = buildingtxt.Text; lecturer.level = leveltxt.Text; lecturer.rank = ranktxt.Text; ranktxt.Text = lecturer.level + "." + lecturer.eid; LectureController ctrl = new LectureController(); ctrl.UpdateLecturer(lecturer); nametxt.Text = ""; eidtxt.Text = ""; factxt.Text = ""; depttxt.Text = ""; centertxt.Text = ""; buildingtxt.Text = ""; leveltxt.Text = ""; ranktxt.Text = ""; eidtxt.ReadOnly = false; lecturerTble.DataSource = ctrl.getdatatoTable(); addLec.Enabled = true; } else { MessageBox.Show("Please Fill the all the required fields ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void delLec_Click(object sender, EventArgs e) { Lecturer lecturer = new Lecturer(); lecturer.eid = eidtxt.Text; LectureController lectureController = new LectureController(); lectureController.DeleteLecturer(lecturer); nametxt.Text = ""; eidtxt.Text = ""; factxt.Text = ""; depttxt.Text = ""; centertxt.Text = ""; buildingtxt.Text = ""; leveltxt.Text = ""; ranktxt.Text = ""; eidtxt.ReadOnly = false; lecturerTble.DataSource = lectureController.getdatatoTable(); }
public void Setup() { var entities = new List <Lecture> { new Lecture { Id = 1, CourseId = 1, Course = new Course { Id = 1, Name = "Test" }, Name = "Test", StudentLectures = new List <StudentLecture> { new StudentLecture { StudentId = 1, LectureId = 1, Attendance = false } }, Homeworks = new List <Homework>() }, new Lecture { Id = 2, CourseId = 2, Course = new Course { Id = 2, Name = "Test2" }, Name = "Test2", StudentLectures = new List <StudentLecture> { new StudentLecture { StudentId = 2, LectureId = 2, Attendance = true }, new StudentLecture { StudentId = 1, LectureId = 2, Attendance = true } }, Homeworks = new List <Homework>() } }; var config = new MapperConfiguration(opts => { opts.AddProfile(new HomeworkProfile()); opts.AddProfile(new AttendanceProfile()); opts.AddProfile(new CourseProfile()); opts.AddProfile(new StudentProfile()); opts.AddProfile(new LecturerProfile()); opts.AddProfile(new LectureProfile()); }); var collection = entities.AsQueryable().BuildMock(); var mapper = config.CreateMapper(); Service = new Mock <ILectureService>(); Logger = new Mock <ILogger <LectureController> >(); Service.Setup(x => x.GetAllLectures()) .Returns(collection.Object); Service.Setup(x => x.GetAllLecturesWithCourse()) .Returns(collection.Object); Service.Setup(x => x.GetAllLecturesWithHomeworks()) .Returns(collection.Object); Service.Setup(x => x.GetAllLecturesWithStudents()) .Returns(collection.Object); Service.Setup(x => x.GetLectureById(It.IsAny <int>())) .Returns((int id) => Task.Run(() => entities.Find(t => t.Id == id))); Service.Setup(x => x.GetLectureWithCourseById(It.IsAny <int>())) .Returns((int id) => Task.Run(() => entities.Find(t => t.Id == id))); Service.Setup(x => x.GetLectureWithHomeworksById(It.IsAny <int>())) .Returns((int id) => Task.Run(() => entities.Find(t => t.Id == id))); Service.Setup(x => x.GetLectureWithStudentsById(It.IsAny <int>())) .Returns((int id) => Task.Run(() => entities.Find(t => t.Id == id))); Service.Setup(x => x.CreateLecture(It.IsAny <Lecture>())) .Callback((Lecture lecture) => entities.Add(lecture)); Service.Setup(x => x.UpdateLecture(It.IsAny <Lecture>())) .Callback((Lecture lecture) => entities[entities.FindIndex(x => x.Id == lecture.Id)] = lecture); Service.Setup(x => x.DeleteLecture(It.IsAny <Lecture>())) .Callback((Lecture lecture) => entities.RemoveAt(entities.FindIndex(x => x.Id == lecture.Id))); Service.Setup(x => x.AddHomeworkToLecture(It.IsAny <int>(), It.IsAny <string>())) .Callback((int id, string task) => entities[entities.FindIndex(x => x.Id == id)].Homeworks.Add(new Homework { LectureId = id, Task = task })); Service.Setup(x => x.MarkAttendance(It.IsAny <int>(), It.IsAny <IEnumerable <int> >())) .Callback((int id, IEnumerable <int> studentIds) => MarkAttendance(id, studentIds, entities)); Service.Setup(x => x.MarkAbsence(It.IsAny <int>(), It.IsAny <IEnumerable <int> >())) .Callback((int id, IEnumerable <int> studentIds) => MarkAbsence(id, studentIds, entities)); Service.Setup(x => x.GetLecturerOfLecture(It.IsAny <int>())) .ReturnsAsync(new Lecturer { Id = 1, Name = "Q" }); Service.Setup(x => x.GetNumberOfStudentLecturesMissed(It.IsAny <int>(), It.IsAny <int>())) .ReturnsAsync(1); Controller = new LectureController(Service.Object, mapper, Logger.Object); }