public void DeleteCourse(Course course) { Contract.Requires<ArgumentNullException>(course != null, "The course must be non-null!"); using (var context = new SchoolContext()) { context.Courses.Attach(course); context.Courses.Remove(course); if (context.SaveChanges() != 0) { /* if (Logger.IsLoggingEnabled()) { Logger.Write("The course " + course + " was successfully removed!", "General", 2, 2, TraceEventType.Information); }*/ }/* else { if (Logger.IsLoggingEnabled()) { Logger.Write("The course " + course + " was not removed!", "Important", 1, 1, TraceEventType.Error); } }*/ } }
public void AddCorequisiteToCourse(Course course1, Course course2) { if (course1 == null || course2 == null) throw new ArgumentNullException(); course1.Corequisites.Add(course2); course2.Corequisites.Add(course1); }
public void AddCourse(Course course) { Contract.Requires<ArgumentNullException>(course != null, "The course must be non-null!"); using (var context = new SchoolContext()) { context.Courses.Add(course); if (context.SaveChanges() != 0) { if (Logger.IsLoggingEnabled()) { Logger.Write("The course: " + course + " was successfully inserted!", "General", 2, 2, TraceEventType.Information); } } else { if (Logger.IsLoggingEnabled()) { Logger.Write("The course: " + course + " was not inserted!", "Important", 1, 1, TraceEventType.Error); } } } }
public IList<Catalog> GetAllStudentCatalogsForCourse(Student student, Course course) { using (var context = new MyApplicationContext()) { return context.Catalogs.Where(catalog => catalog.Student == student && catalog.Exam.Course == course).ToList(); } }
/// <summary> /// Adds the course. /// </summary> /// <param name="course">The course.</param> public void AddCourse(Course course) { using (var context = new MyApplicationContext()) { context.Courses.Add(course); context.SaveChanges(); } }
public void AddPrerequisiteToCourse(Course course, Course prereq) { if (course == null || prereq == null) throw new ArgumentNullException(); if (IsCoursePrerequisiteForCourse(course, prereq) || IsCoursePrerequisiteForCourse(prereq, course)) throw new InvalidOperationException(); course.Prerequisites.Add(prereq); }
public bool StudentHasPrerequisites(Student student, Course course) { if (course.Prerequisites.Count == 0) return true; foreach (var prereq in course.Prerequisites) if (HasStudentCourse(student, prereq) && StudentPassedCourse(student, prereq)) return true; return false; }
/// <summary> /// Deletes the course. /// </summary> /// <param name="course">The course.</param> public void DeleteCourse(Course course) { using (var context = new MyApplicationContext()) { var newProd = new Course { Id = course.Id }; context.Courses.Attach(newProd); context.Courses.Remove(newProd); context.SaveChanges(); } }
public void TestCourseDelete() { Course course = new Course() { Id = 15 }; courseDataService.Expect(dao => dao.DeleteCourse(course)); courseService.DeleteCourse(course); courseDataService.VerifyAllExpectations(); }
public bool StudentPassedCoursePacket(Student student, Course course) { if (StudentPassedCourse(student, course)) { foreach (var coreqCourse in course.Corequisites) if (!StudentPassedCourse(student, coreqCourse)) return false; return true; } return false; }
public bool IsCoursePrerequisiteForCourse(Course course, Course course2) { if (course == null || course2 == null) throw new ArgumentNullException(); foreach (var prereq in course2.Prerequisites) if (prereq.Id == course.Id) return true; else if (IsCoursePrerequisiteForCourse(course, prereq)) return true; return false; }
public void SetUp() { // a valid course course = new Course() { Name = "Grafica", Credit = 6, MinThreshold = 100, MaxThreshold = 200, Cost = 900 }; }
/// <summary> /// Updates the course. /// </summary> /// <param name="course">The course.</param> /// <exception cref="System.Collections.Generic.KeyNotFoundException"></exception> public void UpdateCourse(Course course) { using (var context = new MyApplicationContext()) { Course courseRef = context.Courses.Where(c => c.Id == course.Id).SingleOrDefault(); if (courseRef != null) { courseRef = course; context.SaveChanges(); } else throw new KeyNotFoundException(); } }
public void ValidateCircularPreRequisites(Course course, ValidationResults results) { // verificarea de prerequisites if (!course.CoursePreRequisites.Any()) return; // Verificarea faptului ca nu exista cicluri intre cursuri (A1 prerequisite pentru A2, A2 pentru A3, ... AN pentru A1) if (CourseHasCircularRequisite(course, null, "CoursePreRequisites")) { results.AddResult(new ValidationResult ( "The course cannot have a circular pre-requisite", results, "ValidationMethod", "error", null) ); } }
public void TestCourseGetById() { int id = 15; Course course = new Course() { Id = id, Name = "Baze de date" }; courseDataService.Stub(dao => dao.GetCourseById(id)).Return(course); Course result = courseService.GetCourseById(id); Assert.AreEqual(id, result.Id); }
// Create public bool AddCourse(Course course) { if (!ValidateCourse(course)) { var sb = new StringBuilder(); foreach (var error in Errors) { sb.Append(error); } throw new ValidationException(sb.ToString()); } DataMapperFactory.GetMapperFactory().CourseMapper.AddCourse(course); return true; }
public void TestAddCourseAlreadyPrerequisiteCourse() { Course course3 = new Course(); Course course2 = new Course(); Course course1 = new Course() { Prerequisites = { course2, course3 } }; courseService.AddPrerequisiteToCourse(course1, course2); }
public void TestIsCoursePrereqNullToObj() { Course course1 = null; Course course2 = new Course(); courseService.IsCoursePrerequisiteForCourse(course1, course2); }
public void TestAddCourseIsPrereqIndirectTree() { Course course1 = new Course(); Course course5 = new Course(); Course course4 = new Course() { Prerequisites = { course5, course1 } }; Course course3 = new Course(); Course course2 = new Course() { Prerequisites = { course3, course4 } }; Assert.IsTrue(courseService.IsCoursePrerequisiteForCourse(course1, course2)); }
public void TestAddCourseIsPrereqIndirect() { Course course3 = new Course(); Course course2 = new Course() { Prerequisites = { course3 } }; Course course1 = new Course() { Prerequisites = { course2 } }; Assert.IsTrue(courseService.IsCoursePrerequisiteForCourse(course3, course1)); }
public void TestAddCourseIsNotPrereqEmptyPrereq() { Course course2 = new Course(); Course course1 = new Course(); Assert.IsFalse(courseService.IsCoursePrerequisiteForCourse(course2, course1)); }
public void TestAddTwoPrerequisite() { Course course1 = new Course() { Id = 1 }; Course course2 = new Course() { Id = 2 }; Course course3 = new Course() { Id = 3 }; courseService.AddPrerequisiteToCourse(course1, course2); courseService.AddPrerequisiteToCourse(course1, course3); Assert.AreEqual(2, course1.Prerequisites.Count); }
// Update public Course UpdateCourse(int courseId, Course course) { if (ValidateCourse(course)) return DataMapperFactory.GetMapperFactory().CourseMapper.UpdateCourse(courseId, course); return null; }
public void TestCourseGetListOfCourses() { Course course1 = new Course() { Id = 11, Name = "Baze de date" }; Course course2 = new Course() { Id = 12, Name = "Grafica" }; IList<Course> courses = new List<Course>() { course1, course2 }; courseDataService.Stub(dao => dao.GetAllCourses()).Return(courses); var result = courseService.GetListOfCourses(); Assert.AreEqual(result.Count, courses.Count); }
private bool ValidateCourse(Course course) { // Se va impune din logica aplicatiei ca pentru cursurile din semesterul 1 sa nu existe prerequisites var semesters = DataMapperFactory.GetMapperFactory().SemesterMapper.GetAllSemesters(); bool flag = true; string message = null; if (semesters.Any() && course.Semesters.Contains(semesters.OrderBy(s => s.StartDate).First()) && course.CoursePreRequisites.Any()) { flag = false; message = "Courses in the first semester cannot have prerequisites!"; } if (course.Semesters.Count > 0 && course.CoursePreRequisites.Any()) { flag = false; message = "Courses in the first semester cannot have prerequisites!"; } if (!flag) Errors.Add(message); var result = Validation.Validate(course); if (!result.IsValid) { var firstOrDefault = result.FirstOrDefault(); if (firstOrDefault != null) Errors.Add(firstOrDefault.Message); } return flag && result.IsValid; }
public void TestAddNullCorequisite() { Course course1 = new Course(); Course course2 = null; courseService.AddCorequisiteToCourse(course1, course2); }
public void DeleteCourse(Course course) { DataMapperFactory.GetMapperFactory().CourseMapper.DeleteCourse(course); }
public void TestAddToNullPrerequisite() { Course course1 = null; Course course2 = new Course(); courseService.AddPrerequisiteToCourse(course1, course2); }
public Course UpdateCourse(int courseId, string name, string description, short credits, decimal cost, string currency, int lowerBound, int upperBound) { var course = new Course { CourseId = courseId, Name = name, Description = description, Credits = credits, Cost = cost, Currency = currency, LowerBound = lowerBound, UpperBound = upperBound }; if(ValidateCourse(course)) return DataMapperFactory.GetMapperFactory() .CourseMapper.UpdateCourse(courseId, name, description, credits, cost, currency); return null; }
public void TestAddPrerequisiteCrossCheck() { Course course1 = new Course(); Course course2 = new Course(); courseService.AddPrerequisiteToCourse(course1, course2); Assert.AreEqual(0, course2.Prerequisites.Count); }