Ejemplo n.º 1
0
        public static void RemoveStudentFromClass()
        {
            var classStore   = new EducationClassStore();
            var studentStore = new UserStore();

            do
            {
                Console.Clear();
                Console.WriteLine("Ta bort student från klass");
                Console.WriteLine();
                Console.WriteLine("Tryck enter för att avbryta");
                string input = UserInput.GetInput <string>("Ange klass-id:");

                if (input == string.Empty)
                {
                    return;
                }

                EducationClass edClass = classStore.FindById(input);

                if (edClass == null)
                {
                    Console.WriteLine("Finns ingen klass med det id:t");
                }
                else
                {
                    input = UserInput.GetInput <string>("Ange student-id:");
                    User student = studentStore.FindById(input);

                    if (student == null)
                    {
                        Console.WriteLine("Studenten finns inte");
                    }
                    else
                    {
                        if (edClass.HasStudent(student.UserName))
                        {
                            bool confirmation =
                                UserInput.AskConfirmation(
                                    $"Vill du ta bort {student.FullName()} från klassen {edClass.ClassId}?");
                            if (confirmation)
                            {
                                List <string> studentList = edClass.GetStudentList();
                                studentList.Remove(student.UserName);
                                Console.WriteLine($"Plockade bort {student.UserName} från klassen");

                                edClass.SetStudentList(studentList);
                                classStore.Save();
                            }
                        }
                    }
                }
            } while (true);
        }
Ejemplo n.º 2
0
        private static void DeleteCourse()
        {
            CourseStore courseStore = new CourseStore();
            GradeStore  gradeStore  = new GradeStore();


            Console.Clear();
            Console.WriteLine("Radera kurs");
            Console.WriteLine();

            string courseId     = UserInput.GetInput <string>("Kurs-id:");
            bool   courseExists = courseStore.FindById(courseId) != null;

            if (!courseExists)
            {
                Console.WriteLine("Kursen finns inte");
                return;
            }

            Course        courseToRemove = courseStore.FindById(courseId);
            List <Course> courseList     = courseStore.All().ToList();
            List <Grade>  grades         = gradeStore.FindByCourseId(courseToRemove.CourseId).ToList();

            bool confirm = UserInput.AskConfirmation($"Vill du radera {courseToRemove.CourseName}?");

            if (confirm && grades.Count == 0)
            {
                courseList.Remove(courseToRemove);
                courseStore = new CourseStore(courseList);
                courseStore.Save();

                Console.WriteLine("Kursen raderad");
            }
            else
            {
                Console.WriteLine("Kursen har betygsatta studenter");
                UserInput.WaitForContinue();
            }
        }
Ejemplo n.º 3
0
        private static void EditCourse()
        {
            CourseStore courseStore = new CourseStore();
            UserStore   userStore   = new UserStore();

            Console.Clear();
            Console.WriteLine("Redigera kurs");
            Console.WriteLine();
            string courseId       = UserInput.GetInput <string>("Kurs-id:");
            Course existingCourse = courseStore.FindById(courseId);

            if (existingCourse == null)
            {
                Console.WriteLine("Kursen finns inte");
                return;
            }

            Course courseToEdit = courseStore.FindById(courseId);

            Console.WriteLine("Tryck enter för att behålla gamla värdet");
            string newCourseId      = UserInput.GetInput <string>("Nytt kurs-id:");
            string newCourseName    = UserInput.GetInput <string>("Nytt kursnamn:");
            string newCourseTeacher = UserInput.GetInput <string>("Ny lärare:");

            Console.WriteLine("TODO: Nytt datum måste anges. YYYY-MM-DD");
            DateTime newCourseStartDate = UserInput.GetDate("Nytt startdatum:");
            DateTime newCourseEndDate   = UserInput.GetDate("Nytt slutdatum:");

            if (newCourseId == string.Empty)
            {
                newCourseId = courseToEdit.CourseId;
            }
            if (newCourseName == string.Empty)
            {
                newCourseName = courseToEdit.CourseName;
            }
            if (newCourseTeacher == string.Empty)
            {
                newCourseTeacher = courseToEdit.CourseTeacher;
            }

            Course newCourse = new Course
            {
                CourseId      = newCourseId,
                CourseName    = newCourseName,
                CourseTeacher = newCourseTeacher,
                StartDate     = newCourseStartDate,
                EndDate       = newCourseEndDate
            };

            Console.WriteLine("Ändra från:");
            PrintCourseInfo(courseToEdit, userStore);
            Console.WriteLine("Ändras till:");
            PrintCourseInfo(newCourse, userStore);

            Console.WriteLine();
            bool confirm = UserInput.AskConfirmation("Vill du spara ändringarna?");

            if (confirm)
            {
                courseStore.Remove(existingCourse.CourseId);
                courseStore.AddItem(newCourse);
                courseStore.Save();
                Console.WriteLine("Ändringar sparade.");
            }
        }
Ejemplo n.º 4
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.º 5
0
        public static void GradeStudentInCourse(User grader)
        {
            var userStore           = new UserStore();
            var educationClassStore = new EducationClassStore();
            var courseStore         = new CourseStore();
            var gradeStore          = new GradeStore();

            List <string> courseList;
            Course        course;
            User          student;

            Console.Clear();
            Console.WriteLine("Betygsätt student");
            Console.WriteLine();

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

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

                if (studentName == string.Empty)
                {
                    return;
                }

                student = userStore.FindById(studentName);

                if (student == null)
                {
                    Console.WriteLine("Finns ingen student med det id:t");
                }
                else
                {
                    EducationClass studentClass =
                        educationClassStore.FindByStudentId(student.UserName);
                    courseList = studentClass.GetCourseList();
                    break;
                }
            } while (true);

            do
            {
                Console.WriteLine("Tryck enter för att avbryta");
                string courseName = UserInput.GetInput <string>("Ange kurs-id:");
                if (courseName == string.Empty)
                {
                    return;
                }
                if (courses.Exists(c => c.CourseId == courseName))
                {
                    if (courseList.Contains(courseName))
                    {
                        course = courseStore.FindById(courseName);
                        break;
                    }

                    Console.WriteLine("Studentens klass läser inte kursen");
                    UserInput.WaitForContinue();
                }
                else
                {
                    Console.WriteLine("Kursen finns inte eller du är inte lärare för den");
                    UserInput.WaitForContinue();
                }
            } while (true);

            GradeLevel gradeLevel = AskForGrade();

            Console.WriteLine($"Student: {student.FullName()} ({student.UserName})");
            Console.WriteLine($"Kurs: {course.CourseName} ({course.CourseId})");
            Console.WriteLine($"Betyg: {gradeLevel}");
            bool confirm = UserInput.AskConfirmation("Betygsätt student?");



            if (confirm)
            {
                var grade = new Grade
                {
                    CourseId  = course.CourseId,
                    StudentId = student.UserName,
                    Result    = gradeLevel
                };

                gradeStore.GradeStudent(student, grade);
                gradeStore.Save();
            }
        }
Ejemplo n.º 6
0
        public User Create(IDataStore <User> userStore, User existingUser = null)
        {
            bool editingExistingUser = false;

            Console.Clear();
            string userName = string.Empty;

            if (existingUser == null)
            {
                Console.WriteLine("Skapa ny användare");
                existingUser = new User();
            }
            else
            {
                Console.WriteLine($"Redigerar {existingUser.FullName()} ({existingUser.UserName})");
                editingExistingUser = true;
                userName            = existingUser.UserName;
            }

            Console.WriteLine();


            bool loopName = false;

            do
            {
                Console.WriteLine("Lämna namnet tomt för att avbryta");
                userName = UserInput.GetEditableField("Användarnamn", existingUser.UserName);

                User checkUser = userStore.FindById(userName);

                if (checkUser != null && existingUser.UserName != userName)
                {
                    Console.WriteLine("Användarnamnet är upptaget");
                    UserInput.WaitForContinue();
                    loopName = true;
                }
                else if (userName == string.Empty)
                {
                    return(null);
                }
                else
                {
                    break;
                }
            } while (loopName);

            Console.Write("Lösenord: ");
            string password = UserInput.GetInput <string>();

            foreach (UserLevel userLevel in Enum.GetValues(typeof(UserLevel)))
            {
                if (userLevel >= _newUserMaxLevel)
                {
                    Console.WriteLine((int)userLevel + " " + userLevel);
                }
            }

            int  chosenLevel;
            bool loopLevel = true;

            do
            {
                Console.Write("Användarnivå:");
                chosenLevel = UserInput.GetInput <int>();

                if (chosenLevel < (int)_newUserMaxLevel)
                {
                    Console.WriteLine("Ogiltig användarnivå");
                }
                else
                {
                    loopLevel = false;
                }
            } while (loopLevel);

            bool   isValid   = false;
            string ssn       = string.Empty;
            string firstName = UserInput.GetEditableField("Förnamn", existingUser.FirstName);
            string lastName  = UserInput.GetEditableField("Efternamn", existingUser.LastName);

            do
            {
                Console.Clear();
                Console.WriteLine("Ange enligt följande: yymmddxxxx");
                string input = UserInput.GetEditableField("Personnummer", existingUser.SSN);
                if (input.Length != 10)
                {
                    Console.WriteLine("Personnummret måste vara 10 tecken");
                }

                else if (!input.IsValidLuhn())
                {
                    Console.WriteLine("Ogiltigt personnummer");
                }
                else
                {
                    ssn     = input;
                    isValid = true;
                }
            } while (!isValid);

            isValid = false;
            string phoneNumber;

            do
            {
                Console.Clear();
                Console.WriteLine("Telefonnummret måste vara 10 siffror långt");
                phoneNumber = UserInput.GetEditableField("Telefonnummer", existingUser.PhoneNumber);

                if (phoneNumber.Length != 10)
                {
                    Console.WriteLine("Telefonnummret måste vara 10 siffror");
                }
                else if (!phoneNumber.IsAllDigits())
                {
                    Console.WriteLine("Endast siffror är tillåtna");
                }
                else
                {
                    isValid = true;
                }
            } while (!isValid);


            existingUser = new User
            {
                UserName    = userName,
                Password    = password,
                UserLevel   = (UserLevel)chosenLevel,
                FirstName   = firstName,
                LastName    = lastName,
                SSN         = ssn,
                PhoneNumber = phoneNumber
            };

            Console.Clear();
            Console.WriteLine($"Användarnamn: {existingUser.UserName}");
            Console.WriteLine($"Lösenord: {existingUser.Password}");
            Console.WriteLine($"Namn: {existingUser.FullName()}");
            Console.WriteLine($"Personnummer: {existingUser.SSN}");
            Console.WriteLine($"Telefonnummer: {existingUser.PhoneNumber}");
            Console.WriteLine($"Användarnivå: {existingUser.UserLevel}");

            bool confirm = UserInput.AskConfirmation("Vill du spara användaren?");

            if (confirm)
            {
                if (editingExistingUser)
                {
                    List <User> userList = userStore.All().Where(u => u.UserName != existingUser.UserName).ToList();
                    userList.Add(existingUser);
                    userStore = new UserStore(userList);
                    Console.WriteLine($"Användare {existingUser.UserName} redigerad");
                }
                else
                {
                    userStore.AddItem(existingUser);
                    Console.WriteLine($"Ny användare {existingUser.UserName} skapad");
                }

                userStore.Save();

                UserInput.WaitForContinue();
            }

            return(existingUser);
        }
Ejemplo n.º 7
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();
                        }
                    }
                }
            }
        }