Beispiel #1
0
        /// <summary>
        /// Public method that queries the course table from the data base to get the record
        /// that matches the course id.
        /// </summary>
        /// <param name="idCourse"> Course ID, Type INT </param>

        public void UpdateDBData(int idCourse, Persistence.Cours courseData)
        {
            try
            {
                using (var connection = new Persistence.LHEntities())
                {
                    var course = connection.Courses
                                 .Where(crse => crse.Course_ID == idCourse)
                                 .FirstOrDefault();
                    course.Course_Name     = courseData.Course_Name;
                    course.Syllabus_Course = courseData.Course_Name;
                    course.Active_Course   = courseData.Active_Course;
                    course.Category_Course = courseData.Category_Course;
                    course.Passing_Score   = courseData.Passing_Score;
                    connection.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                var exception = Util.HandleDbEntityValidationException(e);
                throw exception;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Public method that adds a record to the Classroom table.
        /// </summary>
        public void CreateClassroom(Persistence.Classroom classroom)
        {
            try
            {
                using (var connection = new Persistence.LHEntities())
                {
                    var classrm = new Persistence.Classroom
                    {
                        Begin_Date = DateTime.Today,
                        End_Date   = DateTime.Today,
                        Teacher    = classroom.Teacher,
                        Course_ID  = classroom.Course_ID
                    };
                    connection.Classrooms.Add(classrm);

                    connection.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                var exception = Util.HandleDbEntityValidationException(e);
                throw exception;
            }
            catch (DbUpdateException e)
            {
                var exception = Util.HandleDbUpdateException(e);
                throw exception;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }/// <summary>
Beispiel #3
0
        /// <summary>
        /// Public method that queries the user table from the data base to get the record
        /// that matches the user id.
        /// </summary>
        /// <param name="id">User id. Type int</param>
        /// <returns></returns>
        public void UpdateDBData(int id, Persistence.User userData)
        {
            try
            {
                using (var connection = new Persistence.LHEntities())
                {
                    var user = connection.Users
                                .Where(u => u.User_ID == id)
                                .FirstOrDefault();
                    user.User_Name = userData.User_Name;
                    user.User_Email = userData.User_Email;
                    user.User_Cellphone = userData.User_Cellphone;
                    user.User_hash = userData.User_hash;
                    connection.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                var exception = Util.HandleDbEntityValidationException(e);
                throw exception;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

        }
Beispiel #4
0
 public void DeleteUser(int id)
 {
     try
     {
         using (var connection = new Persistence.LHEntities())
         {
             var user = connection.Users
                         .Where(u => u.User_ID == id)
                         .FirstOrDefault();
             if (user != null)
             {
                 connection.Users.Remove(user);
                 connection.SaveChanges();
             }
         }
     }
     catch (DbEntityValidationException e)
     {
         var exception = Util.HandleDbEntityValidationException(e);
         throw exception;
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Beispiel #5
0
 public void createRecord(int studentID, bool present, int classID)
 {
     try
     {
         using (var connection = new Persistence.LHEntities())
         {
             Persistence.Attendance attendance = new Persistence.Attendance();
             attendance.Classroom_ID = classID;
             attendance.Date_attend  = DateTime.Today;
             attendance.User_ID      = studentID;
             attendance.Present      = present;
             connection.Attendances.Add(attendance);
             connection.SaveChanges();
         }
     }
     catch (DbEntityValidationException e)
     {
         var exception = Util.HandleDbEntityValidationException(e);
         throw exception;
     }
     catch (DbUpdateException e)
     {
         var exception = Util.HandleDbUpdateException(e);
         throw exception;
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Beispiel #6
0
        }//UpdateDBData ends

        /// <summary>
        /// Public method that is in charge to add records to the TASK table.
        /// </summary>
        public void CreateTask(Persistence.Task Task)
        {
            try
            {
                using (var connection = new Persistence.LHEntities())
                {
                    var task = new Persistence.Task
                    {
                        Task_Description = Task.Task_Description,
                        Task_Date        = DateTime.Today,
                    };
                    connection.Tasks.Add(task);

                    connection.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                var exception = Util.HandleDbEntityValidationException(e);
                throw exception;
            }
            catch (DbUpdateException e)
            {
                var exception = Util.HandleDbUpdateException(e);
                throw exception;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }//create task ends
Beispiel #7
0
        /// <summary>
        /// Public method that queries the enrollment table from the data base to get the record
        /// that matches the enrollment id.
        /// </summary>
        /// <param name="idEnrrolment"> Enrollment ID, Type INT </param>

        public void UpdateDBData(int idEnrrolment, Persistence.Enrollment enrollmentmData)
        {
            try
            {
                using (var connection = new Persistence.LHEntities())
                {
                    var enrollment = connection.Enrollments
                                     .Where(classr => classr.Enroll_ID == idEnrrolment)
                                     .FirstOrDefault();
                    enrollment.Date_Enroll  = enrollmentmData.Date_Enroll;
                    enrollment.User_ID      = enrollmentmData.User_ID;
                    enrollment.Classroom_ID = enrollmentmData.Classroom_ID;
                    connection.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                var exception = Util.HandleDbEntityValidationException(e);
                throw exception;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Public method that adds a record to the Enrollment table.
        /// </summary>
        public void CreateEnrollment(int userID, int classID)
        {
            try
            {
                using (var connection = new Persistence.LHEntities())
                {
                    var enroll = new Persistence.Enrollment
                    {
                        Date_Enroll  = DateTime.Today,
                        User_ID      = userID,
                        Classroom_ID = classID,
                    };
                    connection.Enrollments.Add(enroll);

                    connection.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                var exception = Util.HandleDbEntityValidationException(e);
                throw exception;
            }
            catch (DbUpdateException e)
            {
                var exception = Util.HandleDbUpdateException(e);
                throw exception;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }/// <summary>
Beispiel #9
0
        /// <summary>
        /// Public method that adds a record to the course table.
        /// </summary>
        public void CreateCourse(Persistence.Cours course)
        {
            try
            {
                using (var connection = new Persistence.LHEntities())
                {
                    var crs = new Persistence.Cours
                    {
                        Course_Name     = course.Course_Name,
                        Syllabus_Course = course.Syllabus_Course,
                        Active_Course   = course.Active_Course,
                        Category_Course = course.Category_Course,
                        Passing_Score   = course.Passing_Score
                    };
                    connection.Courses.Add(crs);

                    connection.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                var exception = Util.HandleDbEntityValidationException(e);
                throw exception;
            }
            catch (DbUpdateException e)
            {
                var exception = Util.HandleDbUpdateException(e);
                throw exception;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }/// <summary>
Beispiel #10
0
        /// <summary>
        /// Public method that queries the classroom table from the data base to get the record
        /// that matches the classroom id.
        /// </summary>
        /// <param name="idClassroom"> Classroom ID, Type INT </param>

        public void UpdateDBData(int idClassroom, Persistence.Classroom classroomData)
        {
            try
            {
                using (var connection = new Persistence.LHEntities())
                {
                    var classroom = connection.Classrooms
                                    .Where(classr => classr.Classroom_ID == idClassroom)
                                    .FirstOrDefault();
                    classroom.Begin_Date = classroomData.Begin_Date;
                    classroom.End_Date   = classroomData.End_Date;
                    classroom.Teacher    = classroomData.Teacher;
                    connection.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                var exception = Util.HandleDbEntityValidationException(e);
                throw exception;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Beispiel #11
0
 /// <summary>
 /// Private method that queries the user table from the data base to get the records
 /// that match the national id and the role provided by the user.
 /// </summary>
 /// <param name="nationalID">National Id. Type int</param>
 /// <param name="roleType">Role type. Type int</param>
 /// <returns></returns>
 public object FetchUserData(int nationalID, int roleType)
 {
     using (var connection = new Persistence.LHEntities())
     {
         var user = connection.Users
                    .Where(u => u.User_CID == nationalID & u.User_Role_ID == roleType)
                    .ToList();
         return user.Count > 0 ? user[0] : null;
     }
 }
Beispiel #12
0
 /// <summary>
 /// Returns all classes where the student is enrolled
 /// </summary>
 /// <param name="courseID"></param>
 /// <returns></returns>
 public object fetchByTeacher(int teacherID)
 {
     using (var connection = new Persistence.LHEntities())
     {
         var studentList = connection.Classroom_Details
                           .Where(c => c.Teacher_ID == teacherID)
                           .ToList();
         return(studentList);
     }
 }
Beispiel #13
0
 /// <summary>
 /// Returns all classes where the student is enrolled
 /// </summary>
 /// <param name="courseID"></param>
 /// <returns></returns>
 public object fetchByStudent(int systemID)
 {
     using (var connection = new Persistence.LHEntities())
     {
         var studentList = connection.Classroom_Details
                           .Where(c => c.System_ID == systemID)
                           .ToList();
         return(studentList);
     }
 }
Beispiel #14
0
 /// <summary>
 /// Returns all students enrolled in a specific course
 /// </summary>
 /// <param name="courseID"></param>
 /// <returns></returns>
 public object fetchByCourse(int courseID)
 {
     using (var connection = new Persistence.LHEntities())
     {
         var studentList = connection.Classroom_Details
                           .Where(c => c.Course_ID == courseID)
                           .ToList();
         return(studentList);
     }
 }
Beispiel #15
0
 /// <summary>
 /// Method that returns a classroom given a classroom ID
 /// </summary>
 /// <param name="classID">Classroom ID. Type int.</param>
 /// <returns></returns>
 public object FetchClassroom(int classID)
 {
     using (var connection = new Persistence.LHEntities())
     {
         var classroom = connection.Classrooms
                         .Where(c => c.Classroom_ID == classID)
                         .ToList();
         return(classroom.Count > 0 ? classroom[0] : null);
     }
 }
Beispiel #16
0
 /// <summary>
 /// Method that returns a course given a course ID
 /// </summary>
 /// <param name="courseID">Course ID. Type int.</param>
 /// <returns></returns>
 public object FetchCourse(int courseID)
 {
     using (var connection = new Persistence.LHEntities())
     {
         var course = connection.Courses
                      .Where(c => c.Course_ID == courseID)
                      .ToList();
         return(course.Count > 0 ? course[0] : null);
     }
 }
Beispiel #17
0
 public object fetchAttendance(int userID)
 {
     using (var connection = new Persistence.LHEntities())
     {
         var course = connection.Classroom_Attendance
                      .Where(c => c.System_ID == userID)
                      .ToList();
         return(course.Count > 0 ? course[0] : null);
     }
 }
Beispiel #18
0
 public object fetchStudents(int classID)
 {
     using (var connection = new Persistence.LHEntities())
     {
         var course = connection.Student_Enrollments
                      .Where(c => c.Classroom_ID == classID)
                      .ToList();
         return(course.Count > 0 ? course[0] : null);
     }
 }
Beispiel #19
0
 /// <summary>
 /// Returns the list of classes that match a user ID from a student
 /// </summary>
 /// <param name="userID">Type int</param>
 /// <returns></returns>
 public object FetchClassroomListsByStudent(int userID)
 {
     using (var connection = new Persistence.LHEntities())
     {
         var classroom = connection.Classroom_Details
                         .Where(c => c.System_ID == userID)
                         .ToList();
         return(classroom.Count > 0 ? classroom[0] : null);
     }
 }
Beispiel #20
0
 /// <summary>
 /// Returns the list of classes that match a user ID from a volunteer
 /// </summary>
 /// <param name="userID">Type int</param>
 /// <returns></returns>
 public object FetchClassroomListsByTeacher(int userID)
 {
     using (var connection = new Persistence.LHEntities())
     {
         var classroom = connection.Classroom_list
                         .Where(c => c.Teacher_ID == userID)
                         .ToList();
         return(classroom.Count > 0 ? classroom[0] : null);
     }
 }
Beispiel #21
0
 /// <summary>
 /// Returns all active or inactive classrooms.
 /// </summary>
 /// <param name="isActive">Type boolean. True equates active, and false equates inactive</param>
 /// <returns></returns>
 public object FetchClassroomsByStatus(bool isActive)
 {
     using (var connection = new Persistence.LHEntities())
     {
         if (isActive == true)
         {
             var classroom = connection.Classroom_list
                             .Where(c => c.Active_Course == isActive & c.Course_Begin_Date >= DateTime.Today)
                             .ToList();
             return(classroom);
         }
         else
         {
             var classroom = connection.Classroom_list
                             .Where(c => c.Active_Course == isActive & c.Course_End_Date < DateTime.Today)
                             .ToList();
             return(classroom);
         }
     }
 }
Beispiel #22
0
        }//create task ends

        /// <summary>
        /// Public method that removes a record from the TASK table.
        /// </summary>
        /// <param name="idTask"> Task_ID, Type INT </param>
        public void DeleteRecorTask(int idTask)
        {
            try
            {
                using (var connection = new Persistence.LHEntities())
                {
                    var itemToRemove = connection.Tasks.First(t => t.Task_ID == idTask);
                    connection.Tasks.Remove(itemToRemove);
                    connection.SaveChanges();
                }
            }
            catch (DbUpdateException e)
            {
                var exception = Util.HandleDbUpdateException(e);
                throw exception;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }//deleteRecordTask ends
Beispiel #23
0
        }/// <summary>

        /// Public method that deletes a record from the Enrollment table.
        /// </summary>
        /// <param name="idEnrollment"> Enrollment id, Type INT</param>
        public void DeleteRecordEnrollment(int idEnrollment)
        {
            try
            {
                using (var connection = new Persistence.LHEntities())
                {
                    var itemToRemove = connection.Enrollments.First(enroll => enroll.Enroll_ID == idEnrollment);
                    connection.Enrollments.Remove(itemToRemove);
                    connection.SaveChanges();
                }
            }
            catch (DbUpdateException e)
            {
                var exception = Util.HandleDbUpdateException(e);
                throw exception;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Beispiel #24
0
        }/// <summary>

        /// Public method that deletes a record from the Classroom table.
        /// </summary>
        /// <param name="idClassroom"> Classroom id, Type INT</param>
        public void DeleteRecordClassroom(int idClassroom)
        {
            try
            {
                using (var connection = new Persistence.LHEntities())
                {
                    var itemToRemove = connection.Classrooms.First(classr => classr.Classroom_ID == idClassroom);
                    connection.Classrooms.Remove(itemToRemove);
                    connection.SaveChanges();
                }
            }
            catch (DbUpdateException e)
            {
                var exception = Util.HandleDbUpdateException(e);
                throw exception;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Beispiel #25
0
        /// <summary>
        /// Public method that queries the task table from the data base to get the record
        /// that matches the Task_ID.
        /// </summary>
        /// <param name="idTask"> Task_ID, Type INT </param>

        public void UpdateDBData(int idTask, Persistence.Task Task)
        {
            try
            {
                using (var connection = new Persistence.LHEntities())
                {
                    var task = connection.Tasks
                               .Where(t => t.Task_ID == idTask)
                               .FirstOrDefault();
                    task.Task_Description = Task.Task_Description;
                    task.Task_Date        = Task.Task_Date;
                    connection.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                var exception = Util.HandleDbEntityValidationException(e);
                throw exception;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }//UpdateDBData ends
Beispiel #26
0
 private void UploadToDB(Persistence.User person)
 {
     try
     {
         using (var connection = new Persistence.LHEntities())
         {
             var u = new Persistence.User
             {
                 User_CID = person.User_CID,
                 User_Name = person.User_Name,
                 User_Cellphone = person.User_Cellphone,
                 User_Date_of_birth = person.User_Date_of_birth,
                 User_Email = person.User_Email,
                 User_Role_ID = person.User_Role_ID,
                 User_Date_of_entry = DateTime.Today,
                 User_hash = person.User_hash
             };
             connection.Users.Add(u);
             connection.SaveChanges();
         }
     }
     catch (DbEntityValidationException e)
     {
         var exception = Util.HandleDbEntityValidationException(e);
         throw exception;
     }
     catch (DbUpdateException e)
     {
         var exception = Util.HandleDbUpdateException(e);
         throw exception;
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }