Esempio n. 1
0
        }     // end of method

        /// <summary>
        /// DeleteTeacher
        /// Deletes a Teacher object by its Teacher ID
        /// </summary>
        /// <param name="id">(int) identifier of the Teacher</param>
        public void DeleteTeacher(int id)
        {
            PersonList data = DataStore.LoadData();

            data.RemoveAll(person => person is Teacher && (person as Teacher).ID == id);
            DataStore.SaveData();
        } // end of method
Esempio n. 2
0
        }         // end of method

        /// <summary>
        /// DeleteStudent
        /// Finds a Student by the Person ID and deletes the object
        /// </summary>
        /// <param name="id">(string) identifier of the Person</param>
        public void DeleteStudent(string id)
        {
            PersonList data = DataStore.LoadData();

            data.RemoveAll(person => person is Student && (person as Student).ID == id);
            DataStore.SaveData();
        }         // end of method
Esempio n. 3
0
        }         // end of method

        /// <summary>
        /// GetStudents
        /// Finds all the Student objects and
        /// returns them as an enumerable object
        /// holding all the students
        /// </summary>
        /// <returns>List<Student> list of student objects</returns>
        public List <Student> GetStudents()
        {
            PersonList data  = DataStore.LoadData();
            var        query = from person in data
                               let student = person as Student
                                             where student != null
                                             select student;

            return(query.ToList());
        }         // end of method
Esempio n. 4
0
        }         // end of method

        /// <summary>
        /// GetStudent
        /// Finds and returns the Student by the Person ID
        /// </summary>
        /// <param name="id">(string) identifier of the Person</param>
        /// <returns>(Student) student object</returns>
        public Student GetStudent(string id)
        {
            PersonList data  = DataStore.LoadData();
            var        query = from person in data
                               let student = person as Student
                                             where student != null && student.ID == id
                                             select student;

            return(query.FirstOrDefault());
        }         // end of method
Esempio n. 5
0
        } // end of method

        /// <summary>
        /// GetTeachers()
        /// Returns a list of Teacher objects
        /// </summary>
        /// <returns>(List<Teacher>) teachers</returns>
        public List <Teacher> GetTeachers()
        {
            PersonList data  = DataStore.LoadData();
            var        query = from person in data
                               let teacher = person as Teacher
                                             where teacher != null
                                             select teacher;

            return(query.ToList());
        } // end of method
Esempio n. 6
0
        } // end of method

        /// <summary>
        /// GetTeacher
        /// Gets a Teacher object by its Teacher ID
        /// </summary>
        /// <param name="id">(int) identifier of the Teacher</param>
        /// <returns>(Teacher) teacher object</returns>
        public Teacher GetTeacher(int id)
        {
            PersonList data  = DataStore.LoadData();
            var        query = from person in data
                               let teacher = person as Teacher
                                             where teacher != null && teacher.ID == id
                                             select teacher;

            return(query.FirstOrDefault());
        } // end of method
Esempio n. 7
0
		} // end of method

		/// <summary>
		/// Saves the PersonList data
		/// </summary>
		public static void SaveData()
		{
			string path = Path.Combine(Path.GetTempPath(), FILENAME);
			if (m_Data == null)
			{
				m_Data = new PersonList();
			}
			string ser = Serialize(m_Data);
			File.WriteAllText(path, ser);
		} // end of method
Esempio n. 8
0
		} // end of method

		/// <summary>
		/// Loads the PersonList from a file
		/// </summary>
		/// <returns>PersonList data</returns>
		public static PersonList LoadData()
		{
			string path = Path.Combine(Path.GetTempPath(), FILENAME);
			if (m_Data == null && File.Exists(path))
			{
				string ser = File.ReadAllText(path);
				m_Data = Deserialize<PersonList>(ser);
			}
			if (m_Data == null)
			{
				m_Data = new PersonList();
			}
			return m_Data;
		} // end of method
Esempio n. 9
0
        }         // end of method

        /// <summary>
        /// GetPeople
        /// Returns a collection object representing a List<Person>
        /// that is a list of Person objects with the last name
        /// and first name provided
        /// </summary>
        /// <param name="lastName">(string) last name of the Person</param>
        /// <param name="firstName">(string) first name of the Person</param>
        /// <returns>(PersonList) collection of people with the first and last name specified
        /// as an input parameter</returns>
        public PersonList GetPeople(string lastName, string firstName)
        {
            PersonList data  = DataStore.LoadData();
            var        query = data.AsQueryable();

            if (!string.IsNullOrEmpty(lastName))
            {
                query = query.Where(p => p.LastName == lastName);
            }
            if (!string.IsNullOrEmpty(firstName))
            {
                query = query.Where(p => p.FirstName == firstName);
            }
            return(new PersonList(query));
        }         // end of method
Esempio n. 10
0
        /// <summary>
        /// AddStudent
        /// Accepts all necessary values to create a new Student object
        /// </summary>
        /// <param name="lastName">(string) last name of the Person</param>
        /// <param name="firstName">(string) first name of the Person</param>
        /// <param name="dob">(DateTime) date of birth of the Person</param>
        /// <param name="gender">(GenderEnum) gender of the Person</param>
        /// <param name="id">(string) identifier of the Person</param>
        /// <param name="major">(string) major of the Student</param>
        /// <param name="units">(float) completed units of the Student</param>
        /// <param name="gpa">(float) GPA of the student</param>
        /// <returns>Student object</returns>
        public Student AddStudent(string lastName, string firstName, DateTime dob, GenderEnum gender, string id, string major, float units, float gpa)
        {
            PersonList data    = DataStore.LoadData();
            Student    result  = null;
            Student    student = GetStudent(id);

            if (student == null)
            {
                // Student doesn't exist
                result = new Student()
                {
                    ID  = id, LastName = lastName, FirstName = firstName,
                    DOB = dob, Gender = gender, Major = major, Units = units, GPA = gpa
                };
                data.Add(result);
                DataStore.SaveData();
            }
            return(result);
        }         // end of method
Esempio n. 11
0
        }         // end of method

        /// <summary>
        /// AddTeacher
        /// Accepts all necessary values to create a new Teacher object
        /// </summary>
        /// <param name="lastName">(string) last name of the Person</param>
        /// <param name="firstName">(string) first name of the Person</param>
        /// <param name="dob">(DateTime) date of birth of the Person</param>
        /// <param name="gender">(GenderEnum) gender of the Person</param>
        /// <param name="id">(int) identifier of the Teacher</param>
        /// <param name="dateofhire">(DateTine) date of hire of the Teacher</param>
        /// <param name="salary">(int) salary of the Teacher</param>
        /// <returns>(Teacher) teacher object</returns>
        public Teacher AddTeacher(string lastName, string firstName, DateTime dob, GenderEnum gender, int idTeacher, DateTime dateofhire, int salary)
        {
            PersonList data    = DataStore.LoadData();
            Teacher    result  = null;
            Teacher    teacher = GetTeacher(idTeacher);

            if (teacher == null)
            {
                // Teacher doesn't exist, object initialize Teacher
                result = new Teacher()
                {
                    LastName   = lastName,
                    FirstName  = firstName,
                    DOB        = dob,
                    Gender     = gender,
                    ID         = idTeacher,
                    DateOfHire = dateofhire,
                    Salary     = salary
                };
                data.Add(result);
                DataStore.SaveData();
            } // end of if
            return(result);
        }     // end of method