/// <summary>
        /// Un curs poate fi ales cel mult o data de catre un student.
        /// </summary>
        /// <param name="student"></param>
        /// <param name="results"></param>
        internal void ValidateCourseCanOnlyBeChoosenASingleTime(Student student, ValidationResults results)
        {
            if (student.Courses.Where(c => c.CourseId != 0).GroupBy(c => c.CourseId).Any(g => g.Count() > 1))
            {
                results.AddResult(new ValidationResult
                    (
                    "The there are duplicate courses (same id) in the list of courses chosen by the student", results, "ValidationMethod", "error", null)
                    );
                return;
            }

            if (student.Courses.Where(c => c.CourseId != 0).GroupBy(c => new { c.Name, c.Description }).Any(g => g.Count() > 1))
            {
                results.AddResult(new ValidationResult
                   (
                   "The there are duplicate courses (same name & description) in the list of courses chosen by the student", results, "ValidationMethod", "error", null)
                   );
                return;
            }

            if (student.Courses.Where(c => c.CourseId != 0).GroupBy(c => c.Name).Any(g => g.Count() > 1))
            {
                 results.AddResult(new ValidationResult
                    (
                    "The there are duplicate courses in the list of courses (same name) chosen by the student", results, "ValidationMethod", "error", null)
                    );
            }
        }
 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();
     }
 }
        public virtual Student GetStudentForCourses(IStudentMock userMock)
        {
            int noProducts = userMock.GetNumberOfCoursesForStuent();

            if (noProducts >= 0)
            {
                var student = new Student
                {
                    FirstName = "reqwe",
                    LastName = "gfsfgfdfds",
                    CNP = "1234567891234",
                    SID = 123,
                    EnrollmentDate = DateTime.Now,
                    Emails = new[] { new Email("*****@*****.**"), }
                };

                var address = new Address
                {
                    City = "New York",
                    Country = "USA",
                    State = "NYQ",
                    PostalCode = "12345",
                    Street = "Brooklyn 33",
                    Student = student
                };

                return student;
            }
            return null;
        }
 /// <summary>
 /// Adds the student.
 /// </summary>
 /// <param name="student">The student.</param>
 public void AddStudent(Student student)
 {
     using (var context = new MyApplicationContext())
     {
         context.Students.Add(student);
         context.SaveChanges();
     }
 }
 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 student.
 /// </summary>
 /// <param name="student">The student.</param>
 public void DeleteStudent(Student student)
 {
     using (var context = new MyApplicationContext())
     {
         var newProd = new Student { Id = student.Id };
         context.Students.Attach(newProd);
         context.Students.Remove(newProd);
         context.SaveChanges();
     }
 }
        public void TestStudentDelete()
        {
            Student student = new Student() { Id = 14 };

            studentDataService.Expect(dao => dao.DeleteStudent(student));

            studentService.DeleteStudent(student);

            studentDataService.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 CanBeginNewSemester(Student student)
 {
     if (student.Semesters.Count == 0)
         return true;
     var lastSemester = student.Semesters[student.Semesters.Count - 1];
     int creditSum = 0;
     foreach (var course in lastSemester.Courses)
     {
         if (StudentPassedCoursePacket(student, course))
             creditSum += course.Credit;
     }
     return creditSum >= lastSemester.MinCredit;
 }
 /// <summary>
 /// Updates the student.
 /// </summary>
 /// <param name="student">The student.</param>
 /// <exception cref="System.Collections.Generic.KeyNotFoundException"></exception>
 public void UpdateStudent(Student student)
 {
     using (var context = new MyApplicationContext())
     {
         Student studentRef = context.Students.Where(c => c.Id == student.Id).SingleOrDefault();
         if (studentRef != null)
         {
             studentRef = student;
             context.SaveChanges();
         }
         else
             throw new KeyNotFoundException();
     }
 }
        public void TestStudentAdd()
        {
            Student student = new Student()
            {
                Id = 15,
                FirstName = "Alex"
            };

            studentDataService.Expect(dao => dao.AddStudent(student));

            studentService.AddStudent(student);

            studentDataService.VerifyAllExpectations();
        }
        // Create
        public void AddStudent(Student student)
        {
            if (!Validate(student))
            {
                var sb = new StringBuilder();
                foreach (var error in Errors)
                {
                    sb.Append(error);
                }
                throw new ValidationException(sb.ToString());
            }

            DataMapperFactory.GetMapperFactory().StudentMapper.AddStudent(student);
        }
 public void SetUp()
 {
     // a valid student
     student = new Student()
     {
         FirstName = "Tamas",
         LastName = "Oprea",
         Address = "Brasov Strada Aurel Vlaicu 56",
         CNP = "1930702080011",
         RegistrationNumber = 206,
         Telephone = "0729 177009",
         Email = "*****@*****.**"
     };
 }
        public void TestStudentGetById()
        {
            int id = 15;
            Student student = new Student()
            {
                Id = id,
                FirstName = "Alex"
            };

            studentDataService.Stub(dao => dao.GetStudentById(id)).Return(student);

            Student result = studentService.GetStudentById(id);

            Assert.AreEqual(id, result.Id);
        }
        public MainWindow()
        {
            InitializeComponent();

            Student student = new Student();
            student.FirstName = "Arpad";
            student.LastName = "Ketestely";
            student.Address = "Aurel Vlaicu 45";
            student.CNP = "1930702080011";

            IStudentService service = new StudentService();
            //service.AddStudent(student);

            Console.WriteLine(service.GetStudentById(1).FirstName);

            IList<Student> students = service.GetListOfStudents();
            foreach(var s in students)
                Console.WriteLine(s.FirstName + " " + s.LastName);
        }
        public void TestStudentCanAttendExamFisrtTime()
        {
            Student student = new Student();
            Course course = new Course() { Id = 12 };

            catalogDataService.Stub(dao => dao.GetAllStudentCatalogsForCourse(student, course)).Return(null);

            Assert.IsTrue(catalogService.CanStudentAttendExamAtCourse(student, course));
        }
 public void UpdateStudent(Student student)
 {
     studentDataService.UpdateStudent(student);
 }
 /// <summary>
 /// Adds the student.
 /// </summary>
 /// <param name="student">The student.</param>
 public void AddStudent(Student student)
 {
     studentDataService.AddStudent(student);
 }
 public void DeleteStudent(Student student)
 {
     studentDataService.DeleteStudent(student);
 }
        public void TestBeginFirstSemester()
        {
            Student student = new Student() { Id = 512 };

            Assert.IsTrue(catalogService.CanBeginNewSemester(student));
        }
 internal void ValidateStudentMuchChooseAtLeastOneEmailOrPhone(Student student, ValidationResults results)
 {
     if (!student.Phones.Any() && !student.Emails.Any())
     {
         results.AddResult(new ValidationResult
             (
             "Please specify at least an email or a phone", results, "ValidationMethod", "error", null)
             );
     }
 }
        public void TestStudentHasToChangeExamOne()
        {
            Catalog catalog1 = new Catalog() { Id = 140, Mark = 4 };
            Catalog catalog2 = new Catalog() { Id = 260, Mark = 4 };
            Catalog catalog3 = new Catalog() { Id = 260, Mark = 4 };

            Course course = new Course() { Id = 12 };
            Student student = new Student() { Semesters = { new Semester() { Courses = { course } } } };

            IList<Catalog> catalogs = new List<Catalog>() { catalog1, catalog2, catalog3 };

            catalogDataService.Stub(dao => dao.GetAllStudentCatalogsForCourse(student, course)).Return(catalogs);

            Assert.AreEqual(1, catalogService.GetCoursesWhichStudentNeedsToChange(student).Count);
        }
        public void TestStudentHasToChangePackageBecausoOTwoExams()
        {
            Catalog catalog1 = new Catalog() { Id = 140, Mark = 4 };
            Catalog catalog2 = new Catalog() { Id = 260, Mark = 4 };
            Catalog catalog3 = new Catalog() { Id = 260, Mark = 4 };
            Catalog catalog4 = new Catalog() { Id = 260, Mark = 4 };

            Course course1 = new Course() { Id = 12 };
            Course course2 = new Course() { Id = 13 };
            course1.Corequisites.Add(course2);
            course2.Corequisites.Add(course1);
            Student student = new Student() { Semesters = { new Semester() { Courses = { course1, course2 } } } };

            IList<Catalog> catalogs1 = new List<Catalog>() { catalog1, catalog2, catalog3 };
            IList<Catalog> catalogs2 = new List<Catalog>() { catalog1, catalog2, catalog4 };

            catalogDataService.Stub(dao => dao.GetAllStudentCatalogsForCourse(student, course1)).Return(catalogs1);
            catalogDataService.Stub(dao => dao.GetAllStudentCatalogsForCourse(student, course2)).Return(catalogs2);

            Assert.AreEqual(2, catalogService.GetCoursesWhichStudentNeedsToChange(student).Count);
        }
        public void TestStudentCantAttendExamAlreadyTookItBoundry()
        {
            Catalog catalog1 = new Catalog() { Id = 140, Mark = 4 };
            Catalog catalog2 = new Catalog() { Id = 260, Mark = 4 };
            Catalog catalog3 = new Catalog() { Id = 260, Mark = 10 };

            Student student = new Student();
            Course course = new Course() { Id = 12 };

            IList<Catalog> catalogs = new List<Catalog>() { catalog1, catalog2, catalog3 };

            catalogDataService.Stub(dao => dao.GetAllStudentCatalogsForCourse(student, course)).Return(catalogs);

            Assert.IsFalse(catalogService.CanStudentAttendExamAtCourse(student, course));
        }
        public void TestCanBeginThirdSemester()
        {
            Student student = new Student()
            {
                Id = 512,
                Semesters =
                {
                    new Semester(),
                    new Semester()
                    {
                        MinCredit = 10,
                        Courses =
                        {
                            new Course() { Id = 1, Credit = 5 },
                            new Course() { Id = 2, Credit = 4 },
                            new Course() { Id = 3, Credit = 4 }
                        }
                    }
                }
            };

            IList<Catalog> catalogs = new List<Catalog>() {
                new Catalog() { Id = 1, Mark = 10 },
                new Catalog() { Id = 2, Mark = 10 },
                new Catalog() { Id = 3, Mark = 10 }
            };

            for (int i = 0; i < student.Semesters[1].Courses.Count; i++)
                catalogDataService.Stub(dao => dao.GetAllStudentCatalogsForCourse(student, student.Semesters[1].Courses[i])).Return(new List<Catalog>() { catalogs[i] });

            Assert.IsTrue(catalogService.CanBeginNewSemester(student));
        }
        public void TestStudentHasCourseInDifferentSemester()
        {
            Student student = new Student()
            {
                Semesters =
                {
                    new Semester()
                    {
                        Courses =
                        {
                            new Course() { Id = 1 },
                            new Course() { Id = 2 }
                        }
                    },
                    new Semester()
                    {
                        Courses =
                        {
                            new Course() { Id = 3 },
                            new Course() { Id = 4 }
                        }
                    }
                }
            };

            Course course = student.Semesters[1].Courses[0];

            Assert.IsTrue(catalogService.HasStudentCourse(student, course));
        }
        public void TestStudentHasTwoPrerequisiteFromTwoSemesters()
        {
            Student student = new Student()
            {
                Id = 512,
                Semesters =
                {
                    new Semester()
                    {
                        Courses =
                        {
                            new Course() { Id = 1},
                            new Course() { Id = 2},
                            new Course() { Id = 3}
                        }
                    },
                    new Semester()
                    {
                        Courses =
                        {
                            new Course() { Id = 4},
                            new Course() { Id = 5},
                            new Course() { Id = 6}
                        }
                    }
                }
            };

            IList<Catalog> catalogs = new List<Catalog>() {
                new Catalog() { Id = 1, Mark = 10 },
                new Catalog() { Id = 2, Mark = 10 },
                new Catalog() { Id = 3, Mark = 10 }
            };

            Course course = new Course() { Id = 10, Prerequisites = { student.Semesters[0].Courses[2], student.Semesters[1].Courses[1] } };

            for (int i = 0; i < student.Semesters[0].Courses.Count; i++)
                catalogDataService.Stub(dao => dao.GetAllStudentCatalogsForCourse(student, student.Semesters[0].Courses[i])).Return(new List<Catalog>() { catalogs[i] });

            Assert.IsTrue(catalogService.StudentHasPrerequisites(student, course));
        }
        public void TestStudentDoesNotHaveCourse()
        {
            Student student = new Student()
            {
                Semesters =
                {
                    new Semester()
                    {
                        Courses =
                        {
                            new Course() { Id = 1 },
                            new Course() { Id = 2 }
                        }
                    }
                }
            };

            Course course = new Course() { Id = 11 };

            Assert.IsFalse(catalogService.HasStudentCourse(student, course));
        }
        public void TestStudentGetListOfStudents()
        {
            Student student1 = new Student()
            {
                Id = 11
            };
            Student student2 = new Student()
            {
                Id = 12
            };
            IList<Student> students = new List<Student>() { student1, student2 };

            studentDataService.Stub(dao => dao.GetAllStudents()).Return(students);

            var result = studentService.GetListOfStudents();

            Assert.AreEqual(result.Count, students.Count);
        }
        public void TestStudentCanAttendExamLastTime()
        {
            Catalog catalog1 = new Catalog() { Id = 140, Mark = 4 };
            Catalog catalog2 = new Catalog() { Id = 260, Mark = 4 };

            Student student = new Student();
            Course course = new Course() { Id = 12 };

            IList<Catalog> catalogs = new List<Catalog>() { catalog1, catalog2 };

            catalogDataService.Stub(dao => dao.GetAllStudentCatalogsForCourse(student, course)).Return(catalogs);

            Assert.IsTrue(catalogService.CanStudentAttendExamAtCourse(student, course));
        }