}//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
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); } }
/// <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>
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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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>
/// <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>
/// <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); } }
}//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
}/// <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); } }
}/// <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); } }
/// <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
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); } }