public void TestDeleteSupervisor() { var serv = new SupervisorService(); var supervisor = new Supervisor() { Name = "Supervisor Studson", Address = "SupervisorRoad", Email = "*****@*****.**", Phone = 12345678 }; var supervisor2 = new Supervisor() { Name = "Supervisor Studson2", Address = "SupervisorRoad2", Email = "[email protected]", Phone = 12345678 }; serv.Create(supervisor); serv.Create(supervisor2); serv.Delete(1); var allSupervisors = serv.GetAll(); int count = allSupervisors.Count; Assert.AreEqual(1, count); Assert.IsFalse(allSupervisors.Exists(x => x.Name == supervisor.Name)); Assert.IsTrue(allSupervisors.Exists(x => x.Name == supervisor2.Name)); }
public RequestsController(RequestService requestService, UserManager <IdentityUser> userManager, SupervisorService supervisorService) { this.requestService = requestService; this.userManager = userManager; this.supervisorService = supervisorService; }
// DELETE: api/Supervisor/5 public IHttpActionResult Delete(int id) { bool result = new SupervisorService().Remove(id); if (result) { return(Ok()); } else { return(Conflict()); } }
private void btnAddSupervisor_Click(object sender, EventArgs e) { Supervisor supervisor = (Supervisor)listViewSupervisors2.SelectedItems[0].Tag; Activity activity = (Activity)listViewSupervisors.SelectedItems[0].Tag; if (listViewSupervisors.SelectedItems.Count < 0) { SupervisorService supervisorService = new SupervisorService(); supervisorService.AddSupervisor(supervisor, activity); } showPanel("Supervisors"); }
private void btnDeleteActivity_Click(object sender, EventArgs e) { if (listViewActivities.SelectedItems.Count > 0) { Activity activities = (Activity)listViewActivities.SelectedItems[0].Tag; activityService.DeleteActivity(activities); List <Activity> ActivityList = activityService.GetActivities(); SupervisorService supervisorService = new SupervisorService(); List <Supervisor> SupervisorList = supervisorService.GetSupervisors(); } }
public void TestCreateSupervisor() { var serv = new SupervisorService(); var supervisor = new Supervisor() { Name = "Supervisor Studson", Address = "SupervisorRoad", Email = "*****@*****.**", Phone = 12345678 }; var newStud = serv.Create(supervisor); Assert.AreEqual(newStud.Name, "Supervisor Studson"); }
public void TestSupervisorAvailability() { var serv = new SupervisorService(); var supervisor = new Supervisor() { Name = "Supervisor Studson", Address = "SupervisorRoad", Email = "*****@*****.**", Phone = 12345678 }; supervisor.IsAvailable = true; Assert.IsTrue(supervisor.IsAvailable); }
public void TestGetAllSupervisors() { var serv = new SupervisorService(); var supervisor = new Supervisor() { Name = "Supervisor Studson", Address = "SupervisorRoad", Email = "*****@*****.**", Phone = 12345678 }; serv.Create(supervisor); List <Supervisor> allSupervisors = serv.GetAll(); Assert.AreEqual(1, allSupervisors.Count); }
private void btnDeleteSupervisor_Click(object sender, EventArgs e) { Supervisor supervisor = (Supervisor)listViewSupervisors2.SelectedItems[0].Tag; Activity activity = (Activity)listViewSupervisors.SelectedItems[0].Tag; if (listViewSupervisors2.SelectedItems.Count > 0) { ActivityService activityService = new ActivityService(); SupervisorService supervisorService = new SupervisorService(); DialogResult confirmDelete = MessageBox.Show($"Are you sure you want to remove {supervisor.FirstName} {supervisor.LastName} from {activity.Description}?", $"Removing {supervisor.FirstName} {supervisor.LastName}", MessageBoxButtons.YesNo); if (confirmDelete == DialogResult.Yes) { supervisorService.RemoveSupervisor(supervisor, activity); } } showPanel("Supervisors"); }
public void TestGetSupervisorById() { var serv = new SupervisorService(); var supervisor = new Supervisor() { Name = "Supervisor Studson", Address = "SupervisorRoad", Email = "*****@*****.**", Phone = 12345678 }; var supervisor2 = new Supervisor() { Name = "Supervisor Studson2", Address = "SupervisorRoad2", Email = "[email protected]", Phone = 12345678 }; serv.Create(supervisor); serv.Create(supervisor2); var stud = serv.GetById(2); Assert.AreEqual("Supervisor Studson2", stud.Name); }
public SupervisorServiceTests() { _loggerAdapter = Substitute.For <ILoggerAdapter>(); _nyssContext = Substitute.For <INyssContext>(); _identityUserRegistrationServiceMock = Substitute.For <IIdentityUserRegistrationService>(); _verificationEmailServiceMock = Substitute.For <IVerificationEmailService>(); _nationalSocietyUserService = Substitute.For <INationalSocietyUserService>(); _deleteUserService = Substitute.For <IDeleteUserService>(); var dateTimeProvider = Substitute.For <IDateTimeProvider>(); var applicationLanguages = new List <ApplicationLanguage>(); var applicationLanguagesDbSet = applicationLanguages.AsQueryable().BuildMockDbSet(); _nyssContext.ApplicationLanguages.Returns(applicationLanguagesDbSet); _supervisorService = new SupervisorService(_identityUserRegistrationServiceMock, _nationalSocietyUserService, _nyssContext, _loggerAdapter, _verificationEmailServiceMock, _deleteUserService, dateTimeProvider); _identityUserRegistrationServiceMock.CreateIdentityUser(Arg.Any <string>(), Arg.Any <Role>()).Returns(ci => new IdentityUser { Id = "123", Email = (string)ci[0] }); var nationalSocieties = new List <NationalSociety> { new NationalSociety { Id = _nationalSocietyId1, Name = "Test national society 1" }, new NationalSociety { Id = _nationalSocietyId2, Name = "Test national society 2" } }; var projects = new List <Project> { new Project { Id = _projectId1, NationalSociety = nationalSocieties[0], Name = "project 1", State = ProjectState.Open }, new Project { Id = _projectId2, NationalSociety = nationalSocieties[0], Name = "project 2", State = ProjectState.Open }, new Project { Id = _projectId3, NationalSociety = nationalSocieties[0], Name = "project 3", State = ProjectState.Closed }, new Project { Id = _projectId4, NationalSociety = nationalSocieties[1], Name = "project 4", State = ProjectState.Open }, new Project { Id = _projectId5, NationalSociety = nationalSocieties[1], Name = "project 5", State = ProjectState.Open } }; var users = new List <User> { new AdministratorUser { Id = _administratorId, Role = Role.Administrator }, new SupervisorUser { Id = _supervisorWithDataCollectorsId, Role = Role.Supervisor, EmailAddress = "*****@*****.**", Name = "*****@*****.**", PhoneNumber = "123", AdditionalPhoneNumber = "321", Sex = Sex.Male, DecadeOfBirth = 1990 }, new SupervisorUser { Id = _supervisorWithoutDataCollectorsId, Role = Role.Supervisor, EmailAddress = "*****@*****.**", Name = "*****@*****.**", PhoneNumber = "123456", AdditionalPhoneNumber = "321", Sex = Sex.Male, DecadeOfBirth = 1990 }, new SupervisorUser { Id = _supervisorWithDeletedDataCollectorsId, Role = Role.Supervisor, EmailAddress = "*****@*****.**", Name = "*****@*****.**", PhoneNumber = "123456", AdditionalPhoneNumber = "321", Sex = Sex.Male, DecadeOfBirth = 1990 } }; var supervisorWithDataCollectors = (SupervisorUser)users[1]; var supervisorWithoutDataCollectors = (SupervisorUser)users[2]; var supervisorWithDeletedDataCollectors = (SupervisorUser)users[3]; var supervisorUserProjects = new List <SupervisorUserProject> { new SupervisorUserProject { Project = projects[0], ProjectId = _projectId1, SupervisorUser = supervisorWithDataCollectors, SupervisorUserId = _supervisorWithDataCollectorsId }, new SupervisorUserProject { Project = projects[2], ProjectId = _projectId3, SupervisorUser = supervisorWithDataCollectors, SupervisorUserId = _supervisorWithDataCollectorsId }, new SupervisorUserProject { Project = projects[1], ProjectId = _projectId3, SupervisorUser = supervisorWithoutDataCollectors, SupervisorUserId = _supervisorWithoutDataCollectorsId }, new SupervisorUserProject { Project = projects[0], ProjectId = _projectId1, SupervisorUser = supervisorWithDeletedDataCollectors, SupervisorUserId = _supervisorWithDeletedDataCollectorsId } }; supervisorWithDataCollectors.SupervisorUserProjects = new List <SupervisorUserProject> { supervisorUserProjects[0], supervisorUserProjects[1] }; supervisorWithoutDataCollectors.SupervisorUserProjects = new List <SupervisorUserProject> { supervisorUserProjects[2] }; supervisorWithDeletedDataCollectors.SupervisorUserProjects = new List <SupervisorUserProject> { supervisorUserProjects[3] }; supervisorWithDataCollectors.CurrentProject = supervisorWithDataCollectors.SupervisorUserProjects.Single(p => p.Project.State == ProjectState.Open).Project; supervisorWithoutDataCollectors.CurrentProject = supervisorWithoutDataCollectors.SupervisorUserProjects.Single(p => p.Project.State == ProjectState.Open).Project; supervisorWithDeletedDataCollectors.CurrentProject = supervisorWithDeletedDataCollectors.SupervisorUserProjects.Single(p => p.Project.State == ProjectState.Open).Project; var userNationalSocieties = new List <UserNationalSociety> { new UserNationalSociety { NationalSociety = nationalSocieties[0], NationalSocietyId = _nationalSocietyId1, User = supervisorWithDataCollectors, UserId = _supervisorWithDataCollectorsId }, new UserNationalSociety { NationalSociety = nationalSocieties[0], NationalSocietyId = _nationalSocietyId1, User = supervisorWithoutDataCollectors, UserId = _supervisorWithoutDataCollectorsId }, new UserNationalSociety { NationalSociety = nationalSocieties[0], NationalSocietyId = _nationalSocietyId1, User = supervisorWithDeletedDataCollectors, UserId = _supervisorWithDeletedDataCollectorsId } }; supervisorWithDataCollectors.UserNationalSocieties = new List <UserNationalSociety> { userNationalSocieties[0] }; supervisorWithoutDataCollectors.UserNationalSocieties = new List <UserNationalSociety> { userNationalSocieties[1] }; supervisorWithDeletedDataCollectors.UserNationalSocieties = new List <UserNationalSociety> { userNationalSocieties[2] }; var dataCollectors = new List <DataCollector> { new DataCollector { Id = _dataCollectorId, Supervisor = supervisorWithDataCollectors }, new DataCollector { Id = _deletedDataCollectorId, Supervisor = supervisorWithDeletedDataCollectors, DeletedAt = new DateTime(2020, 01, 01) } }; var supervisorUserProjectsDbSet = supervisorUserProjects.AsQueryable().BuildMockDbSet(); var nationalSocietiesDbSet = nationalSocieties.AsQueryable().BuildMockDbSet(); var projectsDbSet = projects.AsQueryable().BuildMockDbSet(); var usersDbSet = users.AsQueryable().BuildMockDbSet(); var userNationalSocietiesDbSet = userNationalSocieties.AsQueryable().BuildMockDbSet(); var dataCollectorsDbSet = dataCollectors.AsQueryable().BuildMockDbSet(); _nyssContext.NationalSocieties.Returns(nationalSocietiesDbSet); _nyssContext.Projects.Returns(projectsDbSet); _nyssContext.Users.Returns(usersDbSet); _nyssContext.SupervisorUserProjects.Returns(supervisorUserProjectsDbSet); _nyssContext.UserNationalSocieties.Returns(userNationalSocietiesDbSet); _nyssContext.DataCollectors.Returns(dataCollectorsDbSet); _nyssContext.NationalSocieties.FindAsync(1).Returns(nationalSocieties[0]); _nyssContext.NationalSocieties.FindAsync(2).Returns(nationalSocieties[1]); _nationalSocietyUserService.GetNationalSocietyUser <SupervisorUser>(Arg.Any <int>()).Returns(ci => { var user = users.OfType <SupervisorUser>().FirstOrDefault(x => x.Id == (int)ci[0]); if (user == null) { throw new ResultException(ResultKey.User.Registration.UserNotFound); } return(user); }); }
private void showPanel(string panelName) { if (panelName == "Dashboard") { // hide all other panels pnlStudents.Hide(); pnlLecturers.Hide(); pnlRooms.Hide(); pnlDrinks.Hide(); pnlCashRegister.Hide(); pnlReport.Hide(); pnlSupervisors.Hide(); pnlActivities.Hide(); // show dashboard pnlDashboard.Show(); imgDashboard.Show(); } else if (panelName == "Students") { // hide all other panels pnlDashboard.Hide(); imgDashboard.Hide(); pnlLecturers.Hide(); pnlRooms.Hide(); pnlDrinks.Hide(); pnlCashRegister.Hide(); pnlReport.Hide(); pnlSupervisors.Hide(); pnlActivities.Hide(); // show students pnlStudents.Show(); try { studentService = new StudentService(); List <Student> studentList = studentService.GetStudents(); listViewStudents.Items.Clear(); listViewStudents.View = View.Details; foreach (Student student in studentList) { ListViewItem li = new ListViewItem(student.Number.ToString()); li.SubItems.Add(student.Name); li.SubItems.Add(student.LastName); li.SubItems.Add(student.BirthDate.ToString("dd/MM/yyyy")); listViewStudents.Items.Add(li); } } catch (Exception e) { MessageBox.Show("Something went wrong while loading the students: " + e.Message); } } else if (panelName == "Lecturers") // Lecturer Panel { pnlDashboard.Hide(); imgDashboard.Hide(); pnlStudents.Hide(); pnlRooms.Hide(); pnlDrinks.Hide(); pnlCashRegister.Hide(); pnlReport.Hide(); pnlSupervisors.Hide(); pnlActivities.Hide(); pnlLecturers.Show(); try { lecturerService = new LecturerService(); List <Teacher> teacherList = lecturerService.GetTeachers(); listViewLecturers.Items.Clear(); listViewLecturers.View = View.Details; foreach (Teacher teacher in teacherList) { ListViewItem li = new ListViewItem(teacher.Number.ToString()); li.SubItems.Add(teacher.Name); li.SubItems.Add(teacher.LastName); li.SubItems.Add(teacher.Supervisor); listViewLecturers.Items.Add(li); } } catch (Exception e) { MessageBox.Show("Something went wrong while loading the teachers: " + e.Message); } } else if (panelName == "Rooms")//Room Panel { pnlDashboard.Hide(); imgDashboard.Hide(); pnlLecturers.Hide(); pnlStudents.Hide(); pnlDrinks.Hide(); pnlCashRegister.Hide(); pnlReport.Hide(); pnlSupervisors.Hide(); pnlActivities.Hide(); pnlRooms.Show(); try { roomService = new RoomService(); List <Room> roomList = roomService.GetRooms(); listViewRooms.Items.Clear(); listViewRooms.View = View.Details; foreach (Room room in roomList) { ListViewItem li = new ListViewItem(room.Number.ToString()); li.SubItems.Add(room.Capacity.ToString()); li.SubItems.Add(room.Type.ToString()); listViewRooms.Items.Add(li); } } catch (Exception e) { MessageBox.Show("Something went wrong while loading the rooms: " + e.Message); } } else if (panelName == "Drinks") //Room Panel { pnlDashboard.Hide(); imgDashboard.Hide(); pnlLecturers.Hide(); pnlStudents.Hide(); pnlRooms.Hide(); pnlCashRegister.Hide(); pnlReport.Hide(); pnlSupervisors.Hide(); pnlActivities.Hide(); pnlDrinks.Show(); try { drinkService = new DrinkService(); drinkList = drinkService.GetDrinks(); listViewDrinks.Items.Clear(); listViewDrinks.View = View.Details; foreach (Drink drink in drinkList) { ListViewItem li = new ListViewItem(drink.ID.ToString()); li.SubItems.Add(drink.Name); li.SubItems.Add(drink.Token.ToString()); li.SubItems.Add(drink.Stock.ToString()); if (drink.Stock >= 10) { li.SubItems.Add("✔️"); } else { li.SubItems.Add("⚠️"); } listViewDrinks.Items.Add(li); } } catch (Exception e) { MessageBox.Show("Something went wrong while loading the rooms: " + e.Message); } } else if (panelName == "Cash Register") // Drinks Panel { pnlDashboard.Hide(); imgDashboard.Hide(); pnlLecturers.Hide(); pnlStudents.Hide(); pnlRooms.Hide(); pnlDrinks.Hide(); pnlReport.Hide(); pnlSupervisors.Hide(); pnlActivities.Hide(); pnlCashRegister.Show(); try { drinkService = new DrinkService(); drinkList = drinkService.GetDrinks(); listViewDrinks2.Items.Clear(); listViewDrinks2.View = View.Details; foreach (Drink drink in drinkList) { ListViewItem li = new ListViewItem(drink.ID.ToString()); li.SubItems.Add(drink.Name); li.SubItems.Add(drink.Token.ToString()); li.SubItems.Add(drink.Stock.ToString()); li.Tag = drink; if (drink.Stock >= 10) { li.SubItems.Add("✔️"); } else { li.SubItems.Add("⚠️"); } listViewDrinks2.Items.Add(li); } } catch (Exception e) { MessageBox.Show("Something went wrong while loading the drinks: " + e.Message); } try { studentService = new StudentService(); List <Student> studentList = studentService.GetStudents(); listViewStudents2.Items.Clear(); listViewStudents2.View = View.Details; foreach (Student student in studentList) { ListViewItem li = new ListViewItem(student.Number.ToString()); li.SubItems.Add(student.Name); li.SubItems.Add(student.LastName); li.SubItems.Add(student.BirthDate.ToString("dd/MM/yyyy")); li.Tag = student; listViewStudents2.Items.Add(li); } } catch (Exception e) { MessageBox.Show("Something went wrong while loading the students: " + e.Message); } } else if (panelName == "Report") //Report Panel { pnlDashboard.Hide(); imgDashboard.Hide(); pnlLecturers.Hide(); pnlStudents.Hide(); pnlRooms.Hide(); pnlDrinks.Hide(); pnlCashRegister.Hide(); pnlSupervisors.Hide(); pnlActivities.Hide(); pnlReport.Show(); listViewReport.Items.Clear(); listViewReport.View = View.Details; } else if (panelName == "Activities") // Panel Activities { pnlDashboard.Hide(); imgDashboard.Hide(); pnlStudents.Hide(); pnlLecturers.Hide(); pnlRooms.Hide(); pnlDrinks.Hide(); pnlCashRegister.Hide(); pnlReport.Hide(); pnlActivities.Show(); try { ActivityService activityService = new ActivityService(); List <Activity> ActivityList = activityService.GetActivities(); listViewActivities.Items.Clear(); listViewActivities.View = View.Details; foreach (Activity activities in ActivityList) { ListViewItem li = new ListViewItem(activities.ID.ToString()); li.SubItems.Add(activities.Description); li.SubItems.Add(activities.StartDate.ToString("dd/MM/yyyy")); li.SubItems.Add(activities.EndDate.ToString("dd/MM/yyyy")); listViewActivities.Items.Add(li); } } catch (Exception e) { MessageBox.Show("Something went wrong while loading the Activities: " + e.Message); } } else if (panelName == "Supervisors") //Superviser Panel { pnlDashboard.Hide(); imgDashboard.Hide(); pnlLecturers.Hide(); pnlStudents.Hide(); pnlRooms.Hide(); pnlDrinks.Hide(); pnlCashRegister.Hide(); pnlReport.Hide(); pnlActivities.Hide(); pnlSupervisors.Show(); //display activities try { ActivityService activityService = new ActivityService(); List <Activity> ActivityList = activityService.GetActivities(); listViewSupervisors.Items.Clear(); listViewSupervisors.View = View.Details; foreach (Activity activities in ActivityList) { ListViewItem li = new ListViewItem(activities.ID.ToString()); li.SubItems.Add(activities.Description); li.SubItems.Add(activities.StartDate.ToString("dd/MM/yyyy")); li.SubItems.Add(activities.EndDate.ToString("dd/MM/yyyy")); li.Tag = activities; listViewSupervisors.Items.Add(li); } } catch (Exception e) { MessageBox.Show("Something went wrong while loading the Activities: " + e.Message); } try { SupervisorService supervisorService = new SupervisorService(); List <Supervisor> SupervisorList = supervisorService.GetSupervisors(); listViewSupervisors2.Items.Clear(); listViewSupervisors2.View = View.Details; foreach (Supervisor supervisor in SupervisorList) { ListViewItem li = new ListViewItem(supervisor.ActivityId.ToString()); li.SubItems.Add(supervisor.TeacherID.ToString()); li.SubItems.Add(supervisor.FirstName); li.SubItems.Add(supervisor.LastName); li.Tag = supervisor; listViewSupervisors2.Items.Add(li); } } catch (Exception e) { MessageBox.Show("Something went wrong while loading the Supervisors: " + e.Message); } if (listViewSupervisors.SelectedItems.Count > 0) { } } }