//************************************************************* //Method: Initialize // //Purpose: Initializes the DataLayer, will deserialize data // from JSON files into the class' member variables. //************************************************************* public void Initialize() { //Desearlizes Course information into the courses member variable. FileStream cReader = new FileStream("TestCourse.json", FileMode.Open, FileAccess.Read); DataContractJsonSerializer cInput; cInput = new DataContractJsonSerializer(typeof(CourseCollection)); courses = (CourseCollection)cInput.ReadObject(cReader); cReader.Close(); //Desearlizes Professor information into the professors member variable. FileStream pReader = new FileStream("TestProfessor.json", FileMode.Open, FileAccess.Read); DataContractJsonSerializer pInput; pInput = new DataContractJsonSerializer(typeof(ProfessorCollection)); professors = (ProfessorCollection)pInput.ReadObject(pReader); pReader.Close(); //Desearlizes Room information into the rooms member variable. FileStream rReader = new FileStream("TestRoom.json", FileMode.Open, FileAccess.Read); DataContractJsonSerializer rInput; rInput = new DataContractJsonSerializer(typeof(RoomCollection)); rooms = (RoomCollection)rInput.ReadObject(rReader); rReader.Close(); //Desearlizes CourseMeeting information into the courseMeeting member variable. FileStream cmReader = new FileStream("TestCourseMeet.json", FileMode.Open, FileAccess.Read); DataContractJsonSerializer cmInput; cmInput = new DataContractJsonSerializer(typeof(CourseMeetingCollection)); courseMeetings = (CourseMeetingCollection)cmInput.ReadObject(cmReader); cmReader.Close(); }
//************************************************************* //Method: DataLayer // //Purpose: Constructor for the DataLayer class that assigns // default values. //************************************************************* public DataLayer() { courses = new CourseCollection(); professors = new ProfessorCollection(); rooms = new RoomCollection(); courseMeetings = new CourseMeetingCollection(); }
//******************************************************************** //Method: FindByRoom // //Purpose: Performs a search on CourseMeeting elements, elements // that have a RoomID that matches the passed in roomId // will be added to a list and returned. //******************************************************************** public CourseMeetingCollection FindByRoom(int roomId) { CourseMeetingCollection cmc = new CourseMeetingCollection(); cmc.courseMeetings = new List <CourseMeeting>(); foreach (CourseMeeting coursemeeting in courseMeetings) { if (coursemeeting.n_RoomID == roomId) { cmc.courseMeetings.Add(coursemeeting); } } return(cmc); }
//************************************************************************ //Method: FindByProfessor // //Purpose: Performs a search on CourseMeeting elements, elements // that have a ProfessorID that matches the passed in professorId // will be added to a list and returned. //************************************************************************ public CourseMeetingCollection FindByProfessor(int professorId) { CourseMeetingCollection cmc = new CourseMeetingCollection(); cmc.courseMeetings = new List <CourseMeeting>(); foreach (CourseMeeting coursemeeting in courseMeetings) { if (coursemeeting.n_ProfessorID == professorId) { cmc.courseMeetings.Add(coursemeeting); } } return(cmc); }