//public virtual List<User> AvailableEnrollments { get; set; } // Add list for Available Enrollments public List <Enrollment> GetAvailableEnrollments(int unitOfferingId) { var enrollmentData = EnrollmentProcessor.LoadEnrollmentsForUnitOffering(unitOfferingId); var enrollments = new List <Enrollment>( ); foreach (var row in enrollmentData) { var rowData = UserProcessor.SelectUserForUserId(row.UserId); var enrollment = new Enrollment { EnrollmentId = row.EnrollmentId, UserId = row.UserId, Username = rowData.Username, //FirstName = rowData.FirstName, //LastName = rowData.LastName, //EmailAddress = rowData.Email, //PhoneNumber = rowData.PhoneNo, //Password = rowData.Password }; enrollments.Add(enrollment); } return(enrollments); }
public ActionResult Unenrol(int _EnrollmentId) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.UnitOffering)) { return(RedirectToPermissionDenied()); } if (_EnrollmentId <= 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } try { //Attempt to delete Enrolment from database var rowsDeleted = EnrollmentProcessor.DeleteEnrollment(_EnrollmentId); if (rowsDeleted <= 0) { throw new DataException("Unable to Delete Enrollment"); } } catch (DataException _Ex) { //Error Handling ModelState.AddModelError("", $"Unable to save changes due to Error: { _Ex.Message }"); } // Redirects to poage where data is reloaded. return(Redirect(Request.UrlReferrer.ToString( ))); }
public ActionResult AddTeamMember(Enrollment _Enrollment) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.Team)) { return(RedirectToPermissionDenied()); } if (_Enrollment.TeamId <= 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } try { // Ensure a User has been selected //if( _Enrollment.UserId <= 0 ) // throw new DataException( "No Enrolled User Selected." ); var enrollmentData = EnrollmentProcessor.SelectEnrollmentForEnrollmentId(_Enrollment.EnrollmentId); //Check if Student is already a member of this team var rowsFound = EnrollmentProcessor.SelectEnrollmentCountForTeamIdAndUserId(_Enrollment.TeamId, enrollmentData.UserId); if (rowsFound > 0) { throw new DataException($"User is already a member of this Team."); } // Attempt to update enrollment with TeamId EnrollmentProcessor.UpdateEnrollmentWithTeamId(enrollmentData.EnrollmentId, _Enrollment.TeamId); return(Redirect(Request.UrlReferrer.ToString( ))); } catch (Exception _Ex) { // Show Model Errors reload data and return to view. ModelState.AddModelError("", $"Unable to save changes due to Error: {_Ex.Message}"); } // Get the team data var teamModel = TeamProcessor.GetTeamForTeamId(_Enrollment.TeamId); if (teamModel == null) { return(RedirectToUnitOfferingIndex( )); } var projectOffering = ProjectOfferingProcessor.SelectProjectOfferingForProjectOfferingId(teamModel.ProjectofferingId); var team = new Team(teamModel, projectOffering); ViewBag.EnrollmentId = new SelectList(team.GetAvailableEnrollments(team.ProjectOfferingId), "EnrollmentId", "Username", null); return(View(team)); }
/// <summary> /// Navigate to Details page for a Unit Offering /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Details(int id) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.UnitOffering)) { return(RedirectToPermissionDenied()); } if (id == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } try { var unitOfferingModel = UnitOfferingProcessor.SelectUnitOfferingForUnitOfferingId(id); if (unitOfferingModel == null) { return(RedirectToIndexIdNotFound(id)); } var unit = UnitProcessor.SelectUnitForUnitId(unitOfferingModel.UnitId); var teachingPeriod = TeachingPeriodProcessor.SelectTeachingPeriodForTeachingPeriodId(unitOfferingModel.TeachingPeriodId); var year = YearProcessor.SelectYearForYearId(unitOfferingModel.YearId); var convenor = UserProcessor.SelectUserForUserId(unitOfferingModel.ConvenorId); var projectOfferings = ProjectOfferingProcessor.SelectProjectOfferingsForUnitOfferingId(id); var enrollments = EnrollmentProcessor.LoadEnrollmentsForUnitOffering(id); // Convert the model data to non-model data // Pass the data to the view var unitOffering = new UnitOffering(unitOfferingModel, unit, teachingPeriod, year, convenor, projectOfferings, enrollments); ViewBag.UserId = new SelectList(unitOffering.GetStudents( ), "UserId", "Username", null); return(View(unitOffering)); } catch (Exception e) { return(RedirectToIndex(e)); } // Find Unit Offering //db.GetUnitOffering( id ); // Populate Student Drop Down List for to add new Enrollments //PopulateStudentDropDownList( ); // Navigate to View //return View( db ); }
public async Task GetUniqueVolunteersByDate_WhenEnrollmentsFound_ShouldReturnUniqueVolunteersByDate() { //Arrange _repository.Setup(p => p.Enrollments.GetEnrolledAssociates()).ReturnsAsync(_enrollments); var processor = new EnrollmentProcessor(_repository.Object); //Act var response = await processor.GetUniqueVolunteersByDate(null, null, null); //Assert Assert.NotEmpty(response); }
public async Task GetAll_WhenEnrollmentsFound_ShouldReturnAllEnrollments() { //Arrange _repository.Setup(p => p.Enrollments.GetAllAsync()).ReturnsAsync(_enrollments); var processor = new EnrollmentProcessor(_repository.Object); //Act var response = await processor.GetAll(null); //Assert Assert.NotEmpty(response); }
public ActionResult Enrol(Enrollment _Enrollment) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.UnitOffering)) { return(RedirectToPermissionDenied()); } // Ensure Enrollment Model is associated with UnitOffering if (_Enrollment.UnitOfferingId <= null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } try { // Ensure a User has beeen selected. if (_Enrollment.UserId <= 0) { throw new DataException("No User Selected."); } // Check if Student is already enrolled in this unit var rowsFound = EnrollmentProcessor.SelectEnrollmentCountForUnitOfferingIdAndUserId(_Enrollment.UnitOfferingId, _Enrollment.UserId); if (rowsFound > 0) { throw new DataException($"User is already enrolled in this Unit Offering."); } //Attempt to insert new Enrollment to database using data from parameter var data = EnrollmentProcessor.InsertEnrollmentModel(_Enrollment.UnitOfferingId, _Enrollment.UserId); // Checks if Insert operation was successful if not throws an error. if (data == null) { throw new DataException("Enrollmment added was invalid."); } } catch (Exception _Ex) { // Show Model Errors reload data and return to view. ModelState.AddModelError("", $"Unable to save changes due to Error: { _Ex.Message}"); db.GetUnitOffering(_Enrollment.UnitOfferingId); PopulateStudentDropDownList( ); return(View(db)); } // Redirects to page where data is reloaded. return(Redirect(Request.UrlReferrer.ToString( ))); }
public async Task SaveEnrollments_WhenSaveEnrollments_ShouldReturnSaveSuccessAsTrue() { //Arrange _repository.Setup(p => p.Enrollments.AddRangeAsync(_enrollments)).ReturnsAsync(true); _repository.Setup(p => p.Complete()).Returns(1); var processor = new EnrollmentProcessor(_repository.Object); //Act var response = await processor.SaveEnrollments(_enrollments); //Assert var returnValue = Assert.IsType <bool>(response); Assert.True(returnValue); }
public async Task GetBaseLocations_WhenBaseLocationsExist_ShouldReturnAllBaseLocations() { //Arrange var baseLocations = new List <string> { "bl1", "bl2" }; _repository.Setup(p => p.Enrollments.GetBaseLocations()).ReturnsAsync(baseLocations); var processor = new EnrollmentProcessor(_repository.Object); //Act var response = await processor.GetBaseLocations(); //Assert var returnValue = Assert.IsType <List <string> >(response); Assert.NotEmpty(returnValue); }
//public Team( TCABS_DataLibrary.Models.TeamModel team, TCABS_DataLibrary.Models.UnitOfferingModel unitOffering ) //{ // TeamId = team.TeamId; // Name = team.Name; // UnitOfferingId = team.UnitOfferingId; // if( unitOffering?.UnitOfferingId == team.UnitOfferingId ) // { // UnitOffering = new UnitOffering( ) // { // UnitOfferingId = unitOffering.UnitOfferingId // }; // } //} public Team(TCABS_DataLibrary.Models.TeamModel team, TCABS_DataLibrary.Models.ProjectOfferingModel projectOffering) { TeamId = team.TeamId; Name = team.Name; ProjectOfferingId = team.ProjectofferingId; SupervisorId = team.SupervisorId; if (projectOffering?.ProjectOfferingId == team.ProjectofferingId) { GetProjectOffering(team.ProjectofferingId); } var supervisor = UserProcessor.SelectUserForUserId(team.SupervisorId); Supervisor = new User( ) { UserId = supervisor.UserId, Username = supervisor.Username }; var enrollments = EnrollmentProcessor.LoadEnrollmentsForTeam(team.TeamId); Enrollments = new List <Enrollment>( ); foreach (var e in enrollments) { var enrollment = new Enrollment( ) { EnrollmentId = e.EnrollmentId, UserId = e.UserId, UnitOfferingId = e.UnitOfferingId, TeamId = e.TeamId }; var student = UserProcessor.SelectUserForUserId(enrollment.UserId); enrollment.Student = new User( ) { UserId = student.UserId, Username = student.Username }; Enrollments.Add(enrollment); } }
public ActionResult CreateBulkEnrollment(HttpPostedFileBase file) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.UnitOffering)) { return(RedirectToPermissionDenied()); } //Create data which needs to be outside the try-catch block FileCSV data = null; int uploadCount = 0; int failCount = 0; Downloadable errorFile = null; // Enter a try-catch block to make sure any exceptions are caught try { // Decode the CSV file data = new FileCSV(file); // Make sure the headers are correct // This will throw an exception if not data.ValidateHeaders(new string[] { "Unit", // 0 "TeachingPeriod", // 1 "Year", // 2 "Student" // 3 }); // Loop through each row of data // Generate the list of results foreach (string[] row in data.Row) { try { //var unit = db.GetUnitForName( row[ 0 ] ); //if( unit == null ) // throw new DataException( "Unit doesn't exist. " ); //var teachingPeriod = db.GetTeachingPeriodForName( row[ 1 ] ); //if( teachingPeriod == null ) // throw new DataException( "TeachingPeriod doesn't exist. " ); //var year = db.GetYearForYearValue( Int32.Parse( row[ 2 ] ) ); //if( year == null ) // throw new DataException( "Year doesn't exist. " ); var unitOffering = db.GetUnitOfferingForDetails(row[0], row[1], Int32.Parse(row[2])); if (unitOffering == null) { throw new DataException("UnitOffering doesn't exist. "); } var student = db.GetUserForUsername(row[3]); if (student == null) { throw new DataException("Convenor doesn't exist. "); } EnrollmentProcessor.InsertEnrollmentModel(unitOffering.UnitOfferingId, student.UserId); data.SetComment(row, ""); uploadCount++; } catch (Exception e) { data.SetComment(row, e.Message); failCount++; } } // Generate and record the error file, if required if (failCount > 0) { errorFile = Downloadable.CreateCSV(data.GenerateErrorFile( ), "errors.csv"); } } catch (Exception e) { // Record error message for View TempData["UploadError"] = e.Message; } // Record item counts for View if (uploadCount > 0) { TempData["UploadCount"] = uploadCount; } if (failCount > 0) { TempData["FailCount"] = failCount; } Session[FileCSV.SessionLabelUploadErrorLog] = (failCount > 0) ? errorFile : null; // All file processing has been completed // Go to normal create page return(RedirectToAction("Index", "UnitOffering")); }