/// <summary> /// You should implement this function, such that all tests will pass. /// </summary> /// <param name="courseInstanceID">The ID of the course instance which the teacher will be registered to.</param> /// <param name="model">The data which indicates which person should be added as a teacher, and in what role.</param> /// <returns>Should return basic information about the person.</returns> public PersonDTO AddTeacherToCourse(int courseInstanceID, AddTeacherViewModel model) { // does the course exist var course = (from c in _courseInstances.All() where c.ID == courseInstanceID select c).SingleOrDefault(); if (course == null) { throw new AppObjectNotFoundException(); } // Does the person exist var person = (from c in _persons.All() where c.SSN == model.SSN select new PersonDTO { SSN = c.SSN, Name = c.Name }).SingleOrDefault(); if (person == null) { throw new AppObjectNotFoundException(); } // is there a MainTeacher in course int mainTeacher = (from c in _teacherRegistrations.All() where c.CourseInstanceID == courseInstanceID select c).Count(); if (model.Type == TeacherType.MainTeacher && mainTeacher == 1) { throw new AppValidationException("COURSE_ALREADY_HAS_A_MAIN_TEACHER"); } // Is the teacher already assigned to course var registration = (from c in _teacherRegistrations.All() where c.SSN == model.SSN && c.CourseInstanceID == courseInstanceID select c).SingleOrDefault(); if (registration != null && model.Type == TeacherType.AssistantTeacher) { throw new AppValidationException("PERSON_ALREADY_REGISTERED_TEACHER_IN_COURSE"); } else { var teacher = (from c in _persons.All() where c.SSN == model.SSN select new TeacherRegistration { SSN = c.SSN, CourseInstanceID = courseInstanceID, Type = model.Type }).SingleOrDefault(); _teacherRegistrations.Add(teacher); _uow.Save(); } return(person); }
public EditTeacher(int teacherId) { InitializeComponent(); _addTeacherViewModel = new AddTeacherViewModel(new IPSASDbContext()); // add apropriate window objects _addTeacherViewModel.LoadTeacher(teacherId); DataContext = _addTeacherViewModel; }
/// <summary> /// You should implement this function, such that all tests will pass. /// </summary> /// <param name="courseInstanceID">The ID of the course instance which the teacher will be registered to.</param> /// <param name="model">The data which indicates which person should be added as a teacher, and in what role.</param> /// <returns>Should return basic information about the person.</returns> public PersonDTO AddTeacherToCourse(int courseInstanceID, AddTeacherViewModel model) { // TODO: implement this logic! var course = (from c in _courseInstances.All() where c.ID == courseInstanceID select c).SingleOrDefault(); if (course == null) { throw new AppObjectNotFoundException(); } var person = (from p in _persons.All() where p.SSN == model.SSN select new PersonDTO { Name = p.Name, SSN = p.SSN }).SingleOrDefault(); if (person == null) { throw new AppObjectNotFoundException(); } if (model.Type == TeacherType.MainTeacher) { var mainTeacher = (from t in _teacherRegistrations.All() where t.CourseInstanceID == courseInstanceID where t.Type == TeacherType.MainTeacher select t).SingleOrDefault(); if (mainTeacher != null) { throw new AppValidationException("COURSE_ALREADY_HAS_A_MAIN_TEACHER"); } } var teacherRegistration = (from t in _teacherRegistrations.All() where t.CourseInstanceID == courseInstanceID where t.SSN == model.SSN select t).SingleOrDefault(); if (teacherRegistration != null) { throw new AppValidationException("PERSON_ALREADY_REGISTERED_TEACHER_IN_COURSE"); } teacherRegistration = new TeacherRegistration() { CourseInstanceID = courseInstanceID, SSN = model.SSN, Type = TeacherType.MainTeacher }; _teacherRegistrations.Add(teacherRegistration); _uow.Save(); return(person); }
/// <summary> /// You should implement this function, such that all tests will pass. /// </summary> /// <param name="courseInstanceID">The ID of the course instance which the teacher will be registered to.</param> /// <param name="model">The data which indicates which person should be added as a teacher, and in what role.</param> /// <returns>Should return basic information about the person.</returns> public PersonDTO AddTeacherToCourse(int courseInstanceID, AddTeacherViewModel model) { int total = (from tr in _teacherRegistrations.All() where tr.SSN == model.SSN && tr.CourseInstanceID == courseInstanceID select tr).Count(); // If total is not 0 then this teacher is a teacher in this course already if (total == 0) { TeacherRegistration newRegistration = new TeacherRegistration { SSN = model.SSN, CourseInstanceID = courseInstanceID, Type = model.Type }; _teacherRegistrations.Add(newRegistration); return((from p in _persons.All() where model.SSN == p.SSN select new PersonDTO { SSN = p.SSN, Name = p.Name }).First()); } return(null); }
public IActionResult AddTeacher() { AddTeacherViewModel model = new AddTeacherViewModel(); ListOfCountries(model); ListAllDepartments(model); return(View(model)); }
public void AddTeacher_PersonAlreadyRegisteredAsTeacherInCourse() { // Arrange: var model = new AddTeacherViewModel { SSN = SSN_DABS, Type = TeacherType.AssistantTeacher }; // Act: }
public void AddTeacher_InvalidTeacher() { // Arrange: var model = new AddTeacherViewModel { SSN = INVALID_SSN, Type = TeacherType.MainTeacher }; // Act: }
public void AddTeacher_InvalidCourse() { // Arrange: var model = new AddTeacherViewModel { SSN = SSN_GUNNA, Type = TeacherType.AssistantTeacher }; // Act: }
private AddTeacherViewModel ListAllDepartments(AddTeacherViewModel model) { var departments = entityRepository.GetAll(); foreach (var department in departments) { model.Departments.Add(new SelectListItem { Text = department.DepartmentName, Value = department.Id.ToString() }); } return(model); }
public void AddTeacher_AlreadyWithMainTeacher() { // Arrange: var model = new AddTeacherViewModel { SSN = SSN_GUNNA, Type = TeacherType.MainTeacher }; // Act: var dto = _service.AddTeacherToCourse(COURSEID_VEFT_20153, model); }
public void AddTeacher_AlreadyWithMainTeacher() { // Arrange: var model = new AddTeacherViewModel { SSN = SSN_GUNNA, Type = TeacherType.MainTeacher }; // Act: }
public void AddTeacher_InvalidCourse() { // Arrange: var model = new AddTeacherViewModel { SSN = SSN_GUNNA, Type = TeacherType.AssistantTeacher }; // Act: _service.AddTeacherToCourse(INVALID_COURSEID, model); }
private AddTeacherViewModel ListOfCountries(AddTeacherViewModel model) { var countries = countryRepository.GetAllCountries(); foreach (var country in countries) { model.Countries.Add(new SelectListItem { Text = country.CountryName, Value = country.Id.ToString() }); } return(model); }
/// <summary> /// You should implement this function, such that all tests will pass. /// </summary> /// <param name="courseInstanceID">The ID of the course instance which the teacher will be registered to.</param> /// <param name="model">The data which indicates which person should be added as a teacher, and in what role.</param> /// <returns>Should return basic information about the person.</returns> public PersonDTO AddTeacherToCourse(int courseInstanceID, AddTeacherViewModel model) { var course = (from c in _courseInstances.All() where c.ID == courseInstanceID select c).SingleOrDefault(); if (course == null) { throw new AppObjectNotFoundException(); } var newTeacher = (from t in _persons.All() where t.SSN == model.SSN select new PersonDTO { SSN = t.SSN, Name = t.Name, }).SingleOrDefault(); if (newTeacher == null) { throw new AppObjectNotFoundException(); } var isTeacherInCourse = (from t in _teacherRegistrations.All() where t.SSN == newTeacher.SSN && t.CourseInstanceID == courseInstanceID select t).SingleOrDefault(); if (isTeacherInCourse != null) { throw new AppValidationException("The teacher is already registered to this course"); } var isThereAMainTeacher = (from t in _teacherRegistrations.All() where t.CourseInstanceID == courseInstanceID && t.Type == TeacherType.MainTeacher select t).SingleOrDefault(); if (isThereAMainTeacher != null && model.Type == TeacherType.MainTeacher) { throw new AppValidationException("There already is a main theacher in this course"); } var teacherEntity = new TeacherRegistration { SSN = model.SSN, CourseInstanceID = courseInstanceID, Type = model.Type }; _teacherRegistrations.Add(teacherEntity); _uow.Save(); return(newTeacher); }
/// <summary> /// You should implement this function, such that all tests will pass. /// </summary> /// <param name="courseInstanceID">The ID of the course instance which the teacher will be registered to.</param> /// <param name="model">The data which indicates which person should be added as a teacher, and in what role.</param> /// <returns>Should return basic information about the person.</returns> public PersonDTO AddTeacherToCourse(int courseInstanceID, AddTeacherViewModel model) { var course = _courseInstances.All().SingleOrDefault(x => x.ID == courseInstanceID); if (course == null) { throw new AppObjectNotFoundException(ErrorCodes.INVALID_COURSEINSTANCEID); } // TODO: implement this logic! return(null); }
public void AddTeacher_InvalidTeacher() { // Arrange: var model = new AddTeacherViewModel { SSN = INVALID_SSN, Type = TeacherType.MainTeacher }; // Act: _service.AddTeacherToCourse(COURSEID_VEFT_20153, model); }
public void AddTeacher_PersonAlreadyRegisteredAsTeacherInCourse() { // Arrange: var model = new AddTeacherViewModel { SSN = SSN_DABS, Type = TeacherType.AssistantTeacher }; // Act: _service.AddTeacherToCourse(COURSEID_VEFT_20153, model); }
public IActionResult AddTeacher(AddTeacherViewModel addTeacherViewModel) { if (ModelState.IsValid && User.IsInRole("Director")) { var teacher = mapper.Map <Teacher>(addTeacherViewModel); // We map addTeacherViewModel to teacher. this.teacherManager.AddTeacher(teacher); TempData["addedTeacher"] = $"{teacher.Name}"; // Here save for the name of teacher to we show message in the view. return(RedirectToAction(nameof(AllTeachers))); } return(View(addTeacherViewModel)); }
// [ExpectedException(typeof (AppObjectNotFoundException))] public void AddTeacher_InvalidTeacher() { // Arrange: var model = new AddTeacherViewModel { SSN = INVALID_SSN, Type = TeacherType.MainTeacher }; // Note: the method uses test data defined in [TestInitialize] // Act: Assert.Throws <AppObjectNotFoundException>(() => _service.AddTeacherToCourse(COURSEID_VEFT_20153, model)); }
private AddTeacherViewModel States(AddTeacherViewModel model) { ListOfCountries(model); var states = countryRepository.GetRelatedStates(model.CountryId); foreach (var state in states) { model.States.Add(new SelectListItem { Text = state.StateName, Value = state.Id.ToString() }); } return(model); }
// [ExpectedException(typeof(AppObjectNotFoundException))] public void AddTeacher_InvalidCourse() { // Arrange: var model = new AddTeacherViewModel { SSN = SSN_GUNNA, Type = TeacherType.AssistantTeacher }; // Note: the method uses test data defined in [TestInitialize] // Act: Assert.Throws <AppObjectNotFoundException>(() => _service.AddTeacherToCourse(INVALID_COURSEID, model)); }
public void AddTeacher_InvalidCourse() { // Arrange: var model = new AddTeacherViewModel { SSN = SSN_GUNNA, Type = TeacherType.AssistantTeacher }; // Note: the method uses test data defined in [TestInitialize] // Act: _service.AddTeacherToCourse(INVALID_COURSEID, model); }
public void AddTeacher_AlreadyWithMainTeacher() { // Arrange: var model = new AddTeacherViewModel { SSN = SSN_GUNNA, Type = TeacherType.MainTeacher }; // Note: the method uses test data defined in [TestInitialize] // Act: _service.AddTeacherToCourse(COURSEID_VEFT_20153, model); }
// [ExpectedExceptionWithMessage(typeof (AppValidationException), "PERSON_ALREADY_REGISTERED_TEACHER_IN_COURSE")] public void AddTeacher_PersonAlreadyRegisteredAsTeacherInCourse() { // Arrange: var model = new AddTeacherViewModel { SSN = SSN_DABS, Type = TeacherType.AssistantTeacher }; // Note: the method uses test data defined in [TestInitialize] // Act: Exception ex = Assert.Throws <AppValidationException>(() => _service.AddTeacherToCourse(COURSEID_VEFT_20153, model)); Assert.Equal(ex.Message, "PERSON_ALREADY_REGISTERED_TEACHER_IN_COURSE"); }
//[ExpectedExceptionWithMessage(typeof (AppValidationException), "COURSE_ALREADY_HAS_A_MAIN_TEACHER")] public void AddTeacher_AlreadyWithMainTeacher() { // Arrange: var model = new AddTeacherViewModel { SSN = SSN_GUNNA, Type = TeacherType.MainTeacher }; // Note: the method uses test data defined in [TestInitialize] // Act: Exception ex = Assert.Throws <AppValidationException>(() => _service.AddTeacherToCourse(COURSEID_VEFT_20153, model)); Assert.Equal(ex.Message, "COURSE_ALREADY_HAS_A_MAIN_TEACHER"); }
public void AddTeacher_PersonAlreadyRegisteredAsTeacherInCourse() { // Arrange: var model = new AddTeacherViewModel { SSN = SSN_DABS, Type = TeacherType.AssistantTeacher }; // Note: the method uses test data defined in [TestInitialize] // Act: _service.AddTeacherToCourse(COURSEID_VEFT_20153, model); }
public void AddTeacher_InvalidTeacher() { // Arrange: var model = new AddTeacherViewModel { SSN = INVALID_SSN, Type = TeacherType.MainTeacher }; // Act: _service.AddTeacherToCourse(COURSEID_VEFT_20163, model); // Assert: // Should throw exception }
public void AddTeacher_AlreadyWithMainTeacher() { // Arrange: var model = new AddTeacherViewModel { SSN = SSN_GUNNA, Type = TeacherType.MainTeacher }; // Act: // there already is a main teacher in this course _service.AddTeacherToCourse(COURSEID_VEFT_20153, model); // Assert: // Should throw exception }
public void AddTeacher_PersonAlreadyRegisteredAsTeacherInCourse() { // Arrange: var model = new AddTeacherViewModel { SSN = SSN_DABS, Type = TeacherType.AssistantTeacher }; // Act: // DABS is allready in this course _service.AddTeacherToCourse(COURSEID_VEFT_20153, model); // Assert: // Should throw exception }
public IActionResult AddTeacher(int idCourse) { AddTeacherViewModel model = new AddTeacherViewModel(); var course = _courseService.GetCourse(idCourse); model.CourseId = course.Id; model.Title = course.Title; model.Teachers = _userService.GetAllUsersWithRoleNotInCourse("teacher", idCourse) .Select(x => new Teacher { Id = x.Id, Name = x.Name, SurrName = x.Surrname }); return(View(model)); }