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