Esempio n. 1
0
        public void Execute()
        {
            Console.Clear();
            Console.WriteLine("Edit Student GPA");

            StudentRepository   repo     = new StudentRepository(Settings.FilePath);
            ListStudentResponse response = repo.List();

            if (!response.Success)
            {
                ConsoleIO.PrintListErrorMessage(response);
                return;
            }

            List <Student> students = response.Students;

            ConsoleIO.PrintPickListOfStudents(students);
            Console.WriteLine();

            int index = ConsoleIO.GetStudentIndexFromUser("Which student would you like to edit?", students.Count());

            index--;

            Console.WriteLine();

            students[index].GPA = ConsoleIO.GetRequiredDecimalFromUser(string.Format($"Enter the new GPA for {students[index].FirstName} {students[index].LastName}: "));

            repo.Edit(students[index], index);
            Console.WriteLine("GPA updated!");
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Esempio n. 2
0
        public void Execute()
        {
            StudentRepository   repo     = new StudentRepository(Settings.FilePath);
            ListStudentResponse response = repo.List();

            if (!response.Success)
            {
                ConsoleIO.PrintListErrorMessage(response);
                return;
            }
            List <Student> students = response.Students;

            Console.Clear();
            Console.WriteLine("Student List");

            ConsoleIO.PrintStudentListHeader();

            foreach (var student in students)
            {
                Console.WriteLine(ConsoleIO.StudentLineFormat, student.LastName + "," + student.FirstName, student.Major, student.GPA);
            }
            Console.WriteLine();
            Console.WriteLine(ConsoleIO.SeparatorBar);
            Console.WriteLine();
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Esempio n. 3
0
 public static void PrintListErrorMessage(ListStudentResponse response)
 {
     Console.WriteLine("An error occurred loading the student list: ");
     Console.WriteLine(response.Message);
     Console.WriteLine("Press any key to continue...");
     Console.ReadKey();
     return;
 }
Esempio n. 4
0
        public void Execute()
        {
            Console.Clear();
            Console.WriteLine("Remove Student");

            StudentRepository   repo     = new StudentRepository(Settings.FilePath);
            ListStudentResponse response = repo.List();

            if (!response.Success)
            {
                ConsoleIO.PrintListErrorMessage(response);
                return;
            }

            List <Student> students = response.Students;

            ConsoleIO.PrintPickListOfStudents(students);
            Console.WriteLine();

            int index = ConsoleIO.GetStudentIndexFromUser("Which student would you like to delete?", students.Count());

            index--;

            string answer = ConsoleIO.GetYesNoAnswerFromUser($"Are you sure you want to remove {students[index].FirstName} {students[index].LastName}");

            if (answer == "Y")
            {
                repo.Delete(index);
                Console.WriteLine("Student removed!");
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("Remove cancelled!");
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
        }
Esempio n. 5
0
        public ListStudentResponse List()
        {
            ListStudentResponse response = new ListStudentResponse();

            response.Success = true;

            response.Students = new List <Student>();
            try
            {
                using (StreamReader sr = new StreamReader(_filePath))
                {
                    sr.ReadLine();
                    string line;

                    while ((line = sr.ReadLine()) != null)
                    {
                        Student newStudent = new Student();

                        string[] columns = line.Split(',');

                        newStudent.FirstName = columns[0];
                        newStudent.LastName  = columns[1];
                        newStudent.Major     = columns[2];
                        newStudent.GPA       = decimal.Parse(columns[3]);

                        response.Students.Add(newStudent);
                    }
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }


            return(response);
        }