Exemple #1
0
        public Student CreateStudent(UniStudents students)
        {
            Console.WriteLine("Lag en ny student!");

            var name = App.Ask("Navn: ");

            var email = App.Ask("E-post: ");

            return(new Student(name, email, IdLoop(students)));
        }
Exemple #2
0
        public static int IdLoop(UniStudents students)
        {
            var i = students.Students.Count + 1;

            foreach (var student in students.Students)
            {
                if (i == student.Id)
                {
                    i = new Random().Next(1000);
                }
            }

            return(i);
        }
Exemple #3
0
        public static void RunApp(UniStudents students, UniCourses courses)
        {
            while (true)
            {
                var command = Console.ReadLine();

                switch (command)
                {
                case "hjelp": HelpResponse(); break;


                case "ny student":
                {
                    var s = new Student().CreateStudent(students);
                    students.Students.Add(s);
                    WriteL("Student lagt til");
                    break;
                }



                case "fjern student":
                {
                    var q = AskNum("Student-id: ");
                    foreach (var student in students.Students.Where(s => s.Id == q))
                    {
                        courses.RemoveAllCourses(student);
                    }
                    WriteL(students.RemoveStudents(q));
                    break;
                }


                case "vis kurs": WriteL(courses.ShowAllCourses()); break;

                case "vis studenter": WriteL(students.ListStudents()); break;
                }

                if (command == "meld på")
                {
                    var q  = AskNum("student-id: ");
                    var q2 = AskNum("Kurs-id: ");

                    foreach (var student in students.Students.Where(s => s.Id == q))
                    {
                        foreach (var course in courses.Courses.Where(c => c.IdCourse == q2))
                        {
                            WriteL(student.AddCourse(course, student));
                        }
                    }
                }

                if (command == "meld av")
                {
                    var q  = AskNum("student-id: ");
                    var q2 = AskNum("Kurs-id: ");

                    foreach (var student in students.Students.Where(s => s.Id == q))
                    {
                        foreach (var course in courses.Courses.Where(c => c.IdCourse == q2))
                        {
                            WriteL(student.RemoveCourse(course, student));
                        }
                    }
                }


                if (command == "vis student")
                {
                    var q = AskNum("Student-id: ");
                    WriteL(students.FindStudent(q));
                }

                if (command == "cc")
                {
                    Console.Clear();
                }
                if (command == "exit")
                {
                    break;
                }
            }
        }