Beispiel #1
0
        public static bool RemoveUser(User _userToRemove) // Removes a single User
        {
            using (var myDB = new VirtualCollegeContext())
            {
                var users = myDB.Users.ToList();

                var courses = myDB.Courses.
                              Include("Teachers").
                              ToList();

                var lessons = myDB.Lessons.
                              Include("Students").
                              Include("PresentStudents").
                              ToList();

                var grades = myDB.Grades.ToList();

                var payments = myDB.Payments.ToList();

                var addresses = myDB.Addresses.ToList();

                var temp = users.Find(u => u.UserId == _userToRemove.UserId);

                myDB.Users.Remove(temp);

                myDB.SaveChanges();
            }

            return(true);
        }
Beispiel #2
0
        public static bool AddPayment(Payment paymentToAdd)
        {
            bool done = true;

            using (var myDB = new VirtualCollegeContext())
            {
                var users = myDB.Users.
                            ToList();

                var addresses = myDB.Addresses.ToList();

                var courses = myDB.Courses.
                              Include("Teachers").
                              ToList();

                var lessons = myDB.Lessons.
                              Include("Students").
                              Include("PresentStudents").
                              ToList();

                var grades = myDB.Grades.ToList();

                var payments = myDB.Payments.ToList();

                Student userToAddPayment = (Student)users.Find(u => u.UserId == paymentToAdd.Student.UserId);
                userToAddPayment.Payments.Add(new Payment()
                {
                    Amount = paymentToAdd.Amount, Date = paymentToAdd.Date, Student = userToAddPayment
                });
                userToAddPayment.Fees -= paymentToAdd.Amount;
                userToAddPayment.Paid += paymentToAdd.Amount;
                myDB.SaveChanges();
            }
            return(done);
        }
Beispiel #3
0
 public static void RemoveGrade(Grade _gradeToRemove)
 {
     using (var myDB = new VirtualCollegeContext())
     {
         myDB.Grades.Remove(myDB.Grades.Find(_gradeToRemove.GradeId));
         myDB.SaveChanges();
     }
 }
Beispiel #4
0
        public static bool CreateLesson(Lesson _lessonToAdd)
        {
            bool done = false;

            using (var myDB = new VirtualCollegeContext())
            {
                var students = myDB.Users.
                               Include("Lessons").
                               Include("PresentLessons").
                               OfType <Student>().
                               ToList();

                var teachers = myDB.Users.
                               Include("Courses").
                               OfType <Teacher>().
                               ToList();

                var courses = myDB.Courses.
                              Include("Teachers")
                              .ToList();

                var addresses = myDB.Addresses.ToList();

                var lessons = myDB.Lessons.
                              Include("Students").
                              Include("PresentStudents").
                              ToList();

                var grades = myDB.Grades.ToList();

                var payments = myDB.Payments.ToList();

                if (lessons.FindAll(l => l.ToString() == _lessonToAdd.ToString()).Count == 0)
                {
                    Lesson le = new Lesson()
                    {
                        Teacher  = teachers.Find(t => t.UserId == _lessonToAdd.Teacher.UserId),
                        Course   = courses.Find(c => c.CourseId == _lessonToAdd.Course.CourseId),
                        Day      = _lessonToAdd.Day,
                        Duration = _lessonToAdd.Duration,
                        Hour     = _lessonToAdd.Hour,
                        RoomName = _lessonToAdd.RoomName
                    };

                    foreach (Student stu in _lessonToAdd.Students)
                    {
                        le.Students.Add(students.Find(s => s.UserId == stu.UserId));
                    }
                    myDB.Lessons.Add(le);
                    done = true;
                }
                myDB.SaveChanges();
            }
            return(done);
        }
Beispiel #5
0
        public static bool CreateStudent(Student _userToAdd, Address _addressToAdd) // Creates new student if doesn't already exist (checks email)
        {
            bool done = false;

            using (var myDB = new VirtualCollegeContext())
            {
                var students = myDB.Users.
                               Include("Lessons").
                               Include("PresentLessons").
                               OfType <Student>().
                               ToList();

                var teachers = myDB.Users.Include("Courses").OfType <Teacher>().ToList();

                var addresses = myDB.Addresses.ToList();

                var courses = myDB.Courses.
                              Include("Teachers").
                              ToList();

                var lessons = myDB.Lessons.
                              Include("Students").
                              Include("PresentStudents").
                              ToList();

                var grades = myDB.Grades.ToList();

                var payments = myDB.Payments.ToList();

                if (_addressToAdd.AddressLine2 == "")
                {
                    _addressToAdd.AddressLine2 = null;
                }

                Address match = addresses.Find(a => a.ToString() == _addressToAdd.ToString());

                if (students.FindAll(s => s.EmailAddress == _userToAdd.EmailAddress).Count() == 0)
                {
                    if (match == null)
                    {
                        _userToAdd.Address = _addressToAdd;
                    }
                    else
                    {
                        _userToAdd.Address = match;
                    }
                    Student temp = _userToAdd;
                    temp.Tutor = teachers.Find(t => t.UserId == temp.Tutor.UserId);
                    myDB.Users.Add(temp);
                    done = true;
                }
                myDB.SaveChanges();
            }
            return(done);
        }
Beispiel #6
0
 public static void RemoveLesson(Lesson _lessonToRemove)
 {
     if (_lessonToRemove != null)
     {
         using (var myDB = new VirtualCollegeContext())
         {
             myDB.Lessons.Remove(myDB.Lessons.Find(_lessonToRemove.LessonId));
             myDB.SaveChanges();
         }
     }
 }
Beispiel #7
0
 public static void RemoveCourse(Course _courseToRemove)
 {
     if (_courseToRemove != null)
     {
         using (var myDB = new VirtualCollegeContext())
         {
             myDB.Courses.Remove(myDB.Courses.Find(_courseToRemove.CourseId));
             myDB.SaveChanges();
         }
     }
 }
Beispiel #8
0
        public static bool CreateCourse(Course _courseToAdd)
        {
            bool done = false;

            using (var myDB = new VirtualCollegeContext())
            {
                var teachers = myDB.Users.
                               Include("Courses").
                               OfType <Teacher>().
                               ToList();

                var courses = myDB.Courses.
                              Include("Teachers")
                              .ToList();

                var addresses = myDB.Addresses.ToList();

                var lessons = myDB.Lessons.
                              Include("Students").
                              Include("PresentStudents").
                              ToList();

                var grades = myDB.Grades.ToList();

                var payments = myDB.Payments.ToList();

                if (courses.FindAll(c => c.ToString() == _courseToAdd.ToString()).Count == 0)
                {
                    Course co = new Course
                    {
                        Title           = _courseToAdd.Title,
                        Credits         = _courseToAdd.Credits,
                        ReferentTeacher = teachers.Find(x => x.FullName == _courseToAdd.ReferentTeacher.FullName)
                    };

                    foreach (Teacher t in _courseToAdd.Teachers)
                    {
                        co.Teachers.Add(teachers.Find(x => x.FullName == t.FullName));
                    }

                    myDB.Courses.Add(co);
                    done = true;
                }
                myDB.SaveChanges();
            }
            return(done);
        }
Beispiel #9
0
        public static bool UpdateLesson(Lesson _lessonToEdit)
        {
            using (var myDB = new VirtualCollegeContext())
            {
                var students = myDB.Users.
                               Include("Lessons").
                               Include("PresentLessons").
                               OfType <Student>().
                               ToList();

                var teachers = myDB.Users.
                               Include("Courses").
                               OfType <Teacher>().
                               ToList();

                var addresses = myDB.Addresses.ToList();

                var lessons = myDB.Lessons.
                              Include("Students").
                              Include("PresentStudents").
                              ToList();

                var grades = myDB.Grades.ToList();

                var payments = myDB.Payments.ToList();

                var courses = myDB.Courses.
                              Include("Teachers").
                              ToList();

                var lessonToChange = lessons.Find(l => l.LessonId == _lessonToEdit.LessonId);
                lessonToChange.RoomName = _lessonToEdit.RoomName;
                lessonToChange.Day      = _lessonToEdit.Day;
                lessonToChange.Hour     = _lessonToEdit.Hour;
                lessonToChange.Duration = _lessonToEdit.Duration;
                lessonToChange.Teacher  = teachers.Find(t => t.UserId == _lessonToEdit.Teacher.UserId);
                lessonToChange.Students.Clear();
                foreach (Student student in _lessonToEdit.Students)
                {
                    lessonToChange.Students.Add(students.Find(s => s.UserId == student.UserId));
                }

                myDB.SaveChanges();
            }
            return(true);
        }
Beispiel #10
0
        public static bool UpdateCourse(Course _courseToEdit)
        {
            using (var myDB = new VirtualCollegeContext())
            {
                var students = myDB.Users.
                               Include("Lessons").
                               Include("PresentLessons").
                               OfType <Student>().
                               ToList();

                var teachers = myDB.Users.
                               Include("Courses").
                               OfType <Teacher>().
                               ToList();

                var addresses = myDB.Addresses.ToList();

                var lessons = myDB.Lessons.
                              Include("Students").
                              Include("PresentStudents").
                              ToList();

                var grades = myDB.Grades.ToList();

                var payments = myDB.Payments.ToList();

                var courses = myDB.Courses.
                              Include("Teachers").
                              ToList();

                var courseToEdit = courses.Find(c => c.CourseId == _courseToEdit.CourseId);
                courseToEdit.Title           = _courseToEdit.Title;
                courseToEdit.Credits         = _courseToEdit.Credits;
                courseToEdit.ReferentTeacher = teachers.Find(x => x.UserId == _courseToEdit.ReferentTeacher.UserId);
                courseToEdit.Teachers.Clear();
                foreach (Teacher teacher in _courseToEdit.Teachers)
                {
                    courseToEdit.Teachers.Add(teachers.Find(x => x.UserId == teacher.UserId));
                }
                myDB.SaveChanges();
            }
            return(true);
        }
Beispiel #11
0
        public static bool AddGrade(Grade _inputGrade, Student _inputStudent)
        {
            using (var myDB = new VirtualCollegeContext())
            {
                var students = myDB.Users.
                               Include("Lessons").
                               Include("PresentLessons").
                               OfType <Student>().
                               ToList();

                var teachers = myDB.Users.
                               Include("Courses").
                               OfType <Teacher>().
                               ToList();

                var addresses = myDB.Addresses.ToList();

                var lessons = myDB.Lessons.
                              Include("Students").
                              Include("PresentStudents").
                              ToList();

                var grades = myDB.Grades.ToList();

                var payments = myDB.Payments.ToList();

                var courses = myDB.Courses.
                              Include("Teachers").
                              ToList();

                myDB.Grades.Add(new Grade()
                {
                    ExamName    = _inputGrade.ExamName,
                    Course      = courses.Find(c => c.CourseId == _inputGrade.Course.CourseId),
                    Mark        = _inputGrade.Mark,
                    Coefficient = _inputGrade.Coefficient,
                    Student     = students.Find(s => s.UserId == _inputStudent.UserId)
                });

                myDB.SaveChanges();
            }
            return(true);
        }
Beispiel #12
0
        public static bool UpdateGrade(Grade _gradeToEdit)
        {
            using (var myDB = new VirtualCollegeContext())
            {
                var students = myDB.Users.
                               Include("Lessons").
                               Include("PresentLessons").
                               OfType <Student>().
                               ToList();

                var teachers = myDB.Users.
                               Include("Courses").
                               OfType <Teacher>().
                               ToList();

                var addresses = myDB.Addresses.ToList();

                var lessons = myDB.Lessons.
                              Include("Students").
                              Include("PresentStudents").
                              ToList();

                var grades = myDB.Grades.ToList();

                var payments = myDB.Payments.ToList();

                var courses = myDB.Courses.
                              Include("Teachers").
                              ToList();

                var gradeToChange = grades.Find(g => g.GradeId == _gradeToEdit.GradeId);
                gradeToChange.Mark        = _gradeToEdit.Mark;
                gradeToChange.ExamName    = _gradeToEdit.ExamName;
                gradeToChange.Coefficient = _gradeToEdit.Coefficient;

                myDB.SaveChanges();
            }
            return(true);
        }
Beispiel #13
0
        public static bool SetStudentAsPresent(Student _inputStudent, Lesson _inputLesson)
        {
            using (var myDB = new VirtualCollegeContext())
            {
                var students = myDB.Users.
                               Include("Lessons").
                               Include("PresentLessons").
                               OfType <Student>().
                               ToList();

                var teachers = myDB.Users.
                               Include("Courses").
                               OfType <Teacher>().
                               ToList();

                var addresses = myDB.Addresses.ToList();

                var lessons = myDB.Lessons.
                              Include("Students").
                              Include("PresentStudents").
                              Include("PresentStudents").
                              ToList();

                var grades = myDB.Grades.ToList();

                var payments = myDB.Payments.ToList();

                var courses = myDB.Courses.
                              Include("Teachers").
                              ToList();

                lessons.Find(l => l.LessonId == _inputLesson.LessonId).PresentStudents.Add(students.Find(s => s.UserId == _inputStudent.UserId));

                myDB.SaveChanges();
            }
            return(true);
        }
Beispiel #14
0
        public static bool UpdateTeacher(Teacher _userToEdit, Address _addressToEdit)
        {
            bool done = false;

            using (var myDB = new VirtualCollegeContext())
            {
                var students = myDB.Users.
                               Include("Lessons").
                               Include("PresentLessons").
                               OfType <Student>().
                               ToList();

                var teachers = myDB.Users.
                               Include("Courses").
                               OfType <Teacher>().ToList();

                var courses = myDB.Courses.
                              Include("Teachers").
                              ToList();

                var lessons = myDB.Lessons.
                              Include("Students").
                              Include("PresentStudents").
                              ToList();

                var grades          = myDB.Grades.ToList();
                var payments        = myDB.Payments.ToList();
                var addresses       = myDB.Addresses.ToList();
                var teacherToModify = teachers.Find(s => s.UserId == _userToEdit.UserId);
                var oldAddress      = addresses.Find(a => a.AddressId == teacherToModify.Address.AddressId);

                if (_addressToEdit.AddressLine2 == "")
                {
                    _addressToEdit.AddressLine2 = null;
                }

                var     desc  = _addressToEdit.ToString();
                Address match = addresses.Find(a => a.ToString() == desc);

                if (match == null)
                {
                    myDB.Addresses.Add(new Address()
                    {
                        AddressLine1 = _addressToEdit.AddressLine1,
                        AddressLine2 = _addressToEdit.AddressLine2,
                        Postcode     = _addressToEdit.Postcode,
                        City         = _addressToEdit.City,
                        State        = _addressToEdit.State,
                        Country      = _addressToEdit.Country
                    });
                    myDB.SaveChanges();
                    addresses = myDB.Addresses.ToList();
                    teacherToModify.Address = addresses[addresses.Count - 1];
                }
                else
                {
                    teacherToModify.Address = addresses.Find(a => a.AddressId == match.AddressId);
                }

                teacherToModify.EmailAddress = _userToEdit.EmailAddress;
                teacherToModify.Password     = _userToEdit.Password;
                teacherToModify.PhoneNumber  = _userToEdit.PhoneNumber;

                if (oldAddress.Users.Count == 0)
                {
                    myDB.Addresses.Remove(oldAddress);
                }

                done = true;
                myDB.SaveChanges();
            }
            return(done);
        }