Ejemplo n.º 1
0
        public static void ManageStudents(User user)
        {
            Console.Clear();

            Console.WriteLine("Hantera studenter");
            Console.WriteLine();
            Console.WriteLine("1. Visa student-information");
            Console.WriteLine("2. Ändra student-information");
            Console.WriteLine("3. Sätt betyg");
            Console.WriteLine("4. Lägg till student");
            Console.WriteLine("5. Ta bort student");
            Console.WriteLine("6. Visa studieresultat för en student");

            Console.WriteLine();
            Console.Write("Ditt val: ");
            string menuChoice = UserInput.GetInput <string>();

            switch (menuChoice)
            {
            case "1":
                ShowStudentInformation();
                break;

            case "2":
                UserManagerPresenter.ChangeUser(UserLevel.Student);
                break;

            case "3":
                GradePresenter.GradeStudentInCourse(user);
                break;

            case "4":
                ClassListPresenter.AddStudentToClass();
                break;

            case "5":
                ClassListPresenter.RemoveStudentFromClass();
                break;

            case "6":
                ShowStudentInformation();
                break;

            default:
                break;
            }
        }
Ejemplo n.º 2
0
        public static void ShowStudentsForCourse(User user)
        {
            bool isTeacher = user.HasLevel(UserLevel.Teacher);

            do
            {
                CourseStore         courseStore = new CourseStore();
                EducationClassStore classStore  = new EducationClassStore();

                Console.Clear();
                Console.WriteLine("Visa klasslista för kurs");
                Console.WriteLine();

                Console.WriteLine("Tryck enter för att avbryta.");
                string courseName = UserInput.GetInput <string>("Ange kurs-id:");

                if (courseName == string.Empty)
                {
                    break;
                }

                Course course = courseStore.FindById(courseName);

                if (course == null)
                {
                    Console.WriteLine("Finns ingen kurs med det namnet");
                    Console.WriteLine();
                }
                else if (isTeacher && course.CourseTeacher != user.UserName)
                {
                    Console.WriteLine("Du är ej lärare för den kursen.");
                    Console.WriteLine();
                }
                else
                {
                    EducationClass klass        = classStore.FindByCourseId(course.CourseId);
                    List <string>  studentNames = klass.GetStudentList();
                    UserManagerPresenter.PrintStudentList(studentNames);
                }
            } while (true);
        }
Ejemplo n.º 3
0
        public static void GradeStudentGoal(User grader)
        {
            var courseStore = new CourseStore();
            var gradeStore  = new GradeStore();
            var goalStore   = new GoalStore();

            List <Course> courses = GetCourses(grader, courseStore).ToList();


            Course course = CoursePresenter.AskForCourseById();

            if (course == null)
            {
                return;
            }
            if (grader.HasLevel(UserLevel.Teacher) && course.CourseTeacher != grader.UserName)
            {
                Console.WriteLine("Du är ej lärare för den kursen");
                UserInput.WaitForContinue();
                return;
            }

            User           student = UserManagerPresenter.SearchForUser(UserLevel.Student);
            EducationClass klass   = student.GetClass();

            if (klass == null)
            {
                Console.WriteLine("Användaren är inte en student");
                UserInput.WaitForContinue();
                return;
            }
            if (!klass.HasCourse(course.CourseId))
            {
                Console.WriteLine("Klassen läser ej den kursen");
                UserInput.WaitForContinue();
                return;
            }

            List <Goal> goals = goalStore.FindByCourseId(course.CourseId).ToList();

            foreach (Goal g in goals)
            {
                Console.WriteLine($"  {g.GoalId}: {g.Description.Truncate(95)}");
            }

            Console.WriteLine();
            string goalToGrade = UserInput.GetInput <string>("Välj mål att betygsätta:");

            Goal goal = goals.SingleOrDefault(g => g.GoalId == goalToGrade);

            if (goal == null)
            {
                Console.WriteLine($"Finns inget mål med id {goalToGrade}");
                UserInput.WaitForContinue();
                return;
            }

            GradeLevel gradeLevel = AskForGrade();

            var grade = new Grade
            {
                StudentId  = student.UserName,
                CourseId   = course.CourseId,
                CourseGoal = goal.GoalId,
                Result     = gradeLevel
            };

            Console.WriteLine();
            Console.WriteLine($"Student: {student.FullName()}");
            Console.WriteLine($"Kursmål: {goal.Description.Truncate(95)}");
            Console.WriteLine($"Betyg:   {grade.Result}");

            bool confirm = UserInput.AskConfirmation("Spara betyg?");

            if (confirm)
            {
                Grade existingGrade = gradeStore.FindById(grade.GradeId);
                if (existingGrade == null)
                {
                    gradeStore.AddItem(grade);
                    gradeStore.Save();
                }
                else
                {
                    gradeStore.GradeStudent(student, grade);
                    gradeStore.Save();
                }
            }

            Console.WriteLine();
            UserInput.WaitForContinue();
        }
Ejemplo n.º 4
0
        public static void AddStudentToClass()
        {
            var classStore   = new EducationClassStore();
            var studentStore = new UserStore();

            Console.Clear();
            Console.WriteLine("Lägg till student i klass");
            Console.WriteLine();
            Console.WriteLine("Ange klass-id: ");
            string classID        = UserInput.GetInput <string>();
            var    educationClass = classStore.FindById(classID);

            if (educationClass == null)
            {
                Console.WriteLine("Klassen kunde inte hittas");
                return;
            }

            Console.WriteLine("Ange student-id: ");
            string studentID = UserInput.GetInput <string>();

            var studentUser = studentStore.FindById(studentID);

            if (studentUser == null)
            {
                Console.WriteLine("Finns ingen student med det namnet");
            }
            else if (!studentUser.HasLevel(UserLevel.Student))
            {
                Console.WriteLine("Användaren är inte en student");
            }
            else if (educationClass.HasStudent(studentUser.UserName))
            {
                Console.WriteLine("Studenten finns redan i klassen");
            }
            else if (studentUser.HasLevel(UserLevel.Student))
            {
                Console.Clear();
                UserManagerPresenter.PrintUserInfo(studentUser);

                bool accept = UserInput.AskConfirmation("Vill du lägga till studenten till klassen?");
                if (accept)
                {
                    List <string> studentList = educationClass.GetStudentList();

                    studentList.Add(studentUser.UserName);
                    educationClass.SetStudentList(studentList);

                    var educationList = classStore.All().ToList();

                    foreach (var item in educationList)
                    {
                        if (item.ClassId == educationClass.ClassId)
                        {
                            item.SetStudentList(educationClass.GetStudentList());
                            classStore.Save();
                        }
                    }
                }
            }
        }