Exemplo n.º 1
0
        private List <Student> ListStudents(string path)
        {
            var util         = new TxtUtils();
            var studentsList = new List <Student>();

            using (var reader = new StreamReader(path))
            {
                studentsList = util.ListStudentsFromFile(reader);
            }
            return(studentsList);
        }
Exemplo n.º 2
0
        private List <Student> ListStudentsFromFile(StreamReader reader)
        {
            var studentsList = new List <Student>();
            var util         = new TxtUtils();

            while (!reader.EndOfStream)
            {
                var studentToAdd = util.SetValuesString(reader);
                studentsList.Add(studentToAdd);
            }
            return(studentsList);
        }
Exemplo n.º 3
0
        public Student RemoveStudent(Student student)
        {
            var util         = new TxtUtils();
            var writer       = new StringBuilder();
            var studentsList = util.ListStudents(path);

            Student studentToErase = studentsList.Find(x => x.StudentId == student.StudentId);

            studentsList.Remove(studentToErase);

            foreach (var element in studentsList)
            {
                writer.AppendLine($"{element.StudentId},{element.Name},{element.Surname},{element.BirthDate}");
                File.WriteAllText(path, writer.ToString());
            }
            return(student);
        }