public static Student AddNewMenu(string typeOfData) { fileRepository = fileFactory.CreateFileManager(typeOfData); Student exist, student; do { student = new Student(); PropertyInfo[] properties = student.GetType().GetProperties(); foreach (var p in properties) { if (p.Name != "StudentGuid") { System.Console.WriteLine("Plese enter the {0}:", p.Name); var myVal = System.Console.ReadLine(); p.SetValue(student, myVal); } } var students = fileRepository.GetAll(); exist = (students == null ? null : students.Find(s => s.StudentId == student.StudentId)); } while (exist != null); student.StudentGuid = student.GenerateGuid(); return(fileRepository.Add(student)); }
/// <summary> /// Refresh the datagrid with the new data on persistent repository, on an event is fired /// </summary> public void RefreshDataGrid() { if (!File.Exists(localPath)) { GenerateXmlFile(); } if (fileRepository.GetAll() == null) { formDataSet = null; } else { formDataSet = new DataSet(); formDataSet.ReadXml(localPath); studentDataGrid.DataSource = formDataSet.Tables[0]; studentDataGrid.Columns["StudentGuid"].Visible = false; } }
internal static void GetAll(string typeOfData) { fileRepository = fileFactory.CreateFileManager(typeOfData); var listOfStudents = fileRepository.GetAll(); if (listOfStudents != null) { var studentString = ""; foreach (var s in listOfStudents) { studentString = StudentRepository.studentToString(s); System.Console.WriteLine(studentString); } } }
internal static void Remove(string typeOfData) { fileRepository = fileFactory.CreateFileManager(typeOfData); Student deletedStudent, studentToDelete; string id; do { System.Console.WriteLine("Please enter the id of the student:"); id = System.Console.ReadLine(); var students = fileRepository.GetAll(); studentToDelete = students.Find(s => s.StudentId == id); } while (studentToDelete == null); deletedStudent = fileRepository.Delete(id); Console.WriteLine(deletedStudent.StudentGuid.ToString()); }