Пример #1
0
        static void Main(string[] args)
        {
            // Create 4, or more, exercises.
            Exercise loops        = new Exercise("Loops", "C#");
            Exercise localStorage = new Exercise("Local Storage", "Javascript");
            Exercise modules      = new Exercise("Modularization", "Javascript");
            Exercise props        = new Exercise("Props", "React");
            // Create 3, or more, cohorts.
            Cohort day26  = new Cohort("Day Cohort 26");
            Cohort day27  = new Cohort("Day Cohort 27");
            Cohort day28  = new Cohort("Day Cohort 28");
            Cohort night8 = new Cohort("Evening Cohort 8");
            // Create 4, or more, students and assign them to one of the cohorts.
            Student taylor = new Student("Taylor", "Gulley", "taylor1", day27);
            Student mark   = new Student("Mark", "Hale", "mark1", day27);
            Student vik    = new Student("Sathvik", "Reddy", "vik1", day26);
            Student nolan  = new Student("Nolan", "Little", "nolan1", day28);
            Student jon    = new Student("Jon", "Snow", "King of the North", night8);

            day27.ListOfStudents.Add(taylor);
            day27.ListOfStudents.Add(mark);
            day26.ListOfStudents.Add(vik);
            day28.ListOfStudents.Add(nolan);
            night8.ListOfStudents.Add(jon);
            // Create 3, or more, instructors and assign them to one of the cohorts.
            Instructor steve = new Instructor("Steve", "Brownlee", "coach", day27);
            Instructor meg   = new Instructor("Meg", "Ducharme", "meg", day27);
            Instructor kimmy = new Instructor("Kimmy", "Bird", "kimmy", day27);
            Instructor andy  = new Instructor("Andy", "Collins", "andy", day27);

            day27.ListOfInstructors.Add(steve);
            day27.ListOfInstructors.Add(meg);
            day27.ListOfInstructors.Add(kimmy);
            day27.ListOfInstructors.Add(andy);
            // Have each instructor assign 2 exercises to each of the students.
            steve.AssignExercise(taylor, modules);
            steve.AssignExercise(taylor, props);
            meg.AssignExercise(mark, modules);
            meg.AssignExercise(mark, loops);
            kimmy.AssignExercise(vik, props);
            kimmy.AssignExercise(vik, localStorage);
            andy.AssignExercise(nolan, localStorage);
            andy.AssignExercise(nolan, loops);
            steve.AssignExercise(taylor, props);

            List <Student> students = new List <Student>()
            {
                taylor, mark, vik, nolan, jon
            };
            List <Exercise> exercises = new List <Exercise>()
            {
                loops, localStorage, modules, props
            };

            // can reference probes and planets for this, do something like  loop over the exercises then loop over the students to match up who is working on what like Modularization : Taylor, Mark
            // foreach (Student student in students)
            // {
            //     Console.WriteLine($"{student.FirstName} {student.LastName} is working on {student.StudentExercises[0].Name} and {student.StudentExercises[1].Name}");
            // }
            foreach (Exercise exercise in exercises)
            {
                List <string> matchingExercises = new List <string>();
                foreach (Student student in students)
                {
                    if (student.StudentExercises.Contains(exercise))
                    {
                        matchingExercises.Add(student.FirstName);
                    }
                }
                // Console.WriteLine($"{exercise.ExerciseName} is assigned to: {String.Join(", ", matchingExercises)}");
            }
            // Student Exercises Part 2
            List <Instructor> instructors = new List <Instructor>()
            {
                steve, meg, kimmy, andy
            };
            List <Cohort> cohorts = new List <Cohort>()
            {
                day26, day27, day28, night8
            };
            //List exercises for the JavaScript language by using the Where() LINQ method.
            IEnumerable <Exercise> javascriptExercises = from exercise in exercises
                                                         where exercise.ExerciseLanguage == "Javascript"
                                                         select exercise;
            //List students in a particular cohort by using the Where() LINQ method.
            List <Student> cohort27Students = (from student in students
                                               where student.Cohort == day27
                                               select student).ToList();
            //List instructors in a particular cohort by using the Where() LINQ method.
            List <Instructor> cohort27Instructors = instructors.Where(i => i.Cohort == day27).ToList();
            //Sort the students by their last name.
            List <Student> sortedStudents = (from student in students
                                             orderby student.LastName
                                             select student).ToList();
            //Display any students that aren't working on any exercises (Make sure one of your student instances don't have any exercises. Create a new student if you need to.)
            List <Student> studentWithoutExercises = (from student in students
                                                      where student.StudentExercises.Count == 0
                                                      select student
                                                      ).ToList();
            // Which student is working on the most exercises? Make sure one of your students has more exercises than the others.
            var studentWithMostExercises = (from student in students
                                            select new {
                FirstName = student.FirstName,
                Exercises = student.StudentExercises.Count()
            }).OrderByDescending(s => s.Exercises)
                                           .Take(1).ToList()[0];
            // How many students in each cohort?
            // GroupBy gives you a collection of groups - each group has something that it's being grouped by (the key). The group itself is the list of all of the values of the group. Returns a collection of groups.
            // collection of groups (numberOfStudentsInEachCohort)
            // METHOD WAY
            var numberOfStudentsInEachCohort = students.GroupBy(c => c.Cohort.CohortName);

            // looks at every group of students
            foreach (var studentGroup in numberOfStudentsInEachCohort)
            {
                // key is the thing you grouped by
                // Console.WriteLine($"{studentGroup.Key} has {studentGroup.Count()} students");
            }

            // SQL/QUERY WAY
            var totalStudents = from student in students
                                group student by student.Cohort into sorted
                                select new {
                Cohort   = sorted.Key,
                Students = sorted.ToList()
            };

            foreach (var total in totalStudents)
            {
                // Console.WriteLine($"Cohort {total.Cohort.Name} has {total.Students.Count()} students");
            }

            //Using Dapper to query the database
            SqliteConnection db = DatabaseInterface.Connection;

            DatabaseInterface.CheckExerciseTable();
            DatabaseInterface.CheckInstructorsTable();
            DatabaseInterface.CheckCohortsTable();

            List <Exercise> exercisesQuery = db.Query <Exercise>(@"SELECT * FROM Exercise").ToList();

            exercisesQuery.ForEach(ex => Console.WriteLine($"{ex.ExerciseName}"));

            db.Execute($@"
            INSERT INTO Exercise (ExerciseName, ExerciseLanguage) VALUES ('DOM', 'Javascript')
            ");

            List <Exercise> javascriptExercisesQuery = db.Query <Exercise>(@"SELECT * FROM Exercise WHERE ExerciseLanguage == 'Javascript'").ToList();

            javascriptExercisesQuery.ForEach(ex => Console.WriteLine($"This is a Javascript exercise {ex.ExerciseName}"));

            List <Instructor> instructorQuery = db.Query <Instructor>(@"SELECT * FROM Instructor").ToList();

            instructorQuery.ForEach(ins => Console.WriteLine($"{ins.FirstName} {ins.LastName}"));

            List <Cohort> cohortQuery = db.Query <Cohort>(@"SELECT * FROM Cohort").ToList();

            cohortQuery.ForEach(co => Console.WriteLine($"{co.CohortName}"));
        }
Пример #2
0
        static void Main(string[] args)
        {
            ExerciseList ExerciseList = new ExerciseList();

            Exercise Exercise1 = ExerciseList.createExercise("Dictionaries", "C#");
            Exercise Exercise2 = ExerciseList.createExercise("Lists", "C#");
            Exercise Exercise3 = ExerciseList.createExercise("Classes", "C#");
            Exercise Exercise4 = ExerciseList.createExercise("Student Exercises", "C#");

            CohortsList CohortList = new CohortsList();

            Cohort Cohort28 = CohortList.createCohort("Full Stack", "C28");
            Cohort Cohort29 = CohortList.createCohort("Full Stack", "C29");
            Cohort Cohort30 = CohortList.createCohort("Full Stack", "C30");
            Cohort Cohort31 = CohortList.createCohort("Full Stack", "C31");

            InstructorList InstructorList = new InstructorList();

            Instructor Instructor1 = InstructorList.createInstructor("Jisie", "David");
            Instructor Instructor2 = InstructorList.createInstructor("Andy", "Collins");
            Instructor Instructor3 = InstructorList.createInstructor("Kristin", "Norris");
            Instructor Instructor4 = InstructorList.createInstructor("Leah", "Hoefling");

            Instructor1.setSpecialty("Being blunt.");
            Instructor2.setSpecialty("Unknown.");
            Instructor3.setSpecialty("Snacks.");
            Instructor4.setSpecialty("Illustration.");
            Instructor1.SlackHandle = "@jisie";
            Instructor2.SlackHandle = "@andy";
            Instructor3.SlackHandle = "@kristin";
            Instructor4.SlackHandle = "@leah";
            foreach (Instructor Instructor in InstructorList.getAll())
            {
                Cohort31.Assign(Instructor);
            }

            StudentList StudentList = new StudentList();

            Student Student1 = StudentList.createStudent("Anne", "Vick");
            Student Student2 = StudentList.createStudent("Jameka", "Echols");
            Student Student3 = StudentList.createStudent("Chris", "Morgan");
            Student Student4 = StudentList.createStudent("Meag", "Mueller");

            Student1.SlackHandle = "@anne";
            Student2.SlackHandle = "@jameka";
            Student3.SlackHandle = "@chris";
            Student4.SlackHandle = "@meag";
            foreach (Student Student in StudentList.getAll())
            {
                Cohort31.Assign(Student);
            }

            foreach (Student Student in StudentList.getAll())
            {
                Instructor1.AssignExercise(Student, Exercise1);
                Instructor2.AssignExercise(Student, Exercise2);
                Instructor3.AssignExercise(Student, Exercise3);
                Instructor4.AssignExercise(Student, Exercise4);
            }

            foreach (Cohort Cohort in CohortList.AllCohorts())
            {
                Console.WriteLine(Cohort.printInfo());
                Console.WriteLine("-----------------");
            }

            Console.WriteLine("--------------------------");
            Console.WriteLine("PART 2");
            Console.WriteLine("--------------------------");

            Cohort30.Assign(StudentList.createStudent("Larry", "Larryson"));
            Cohort30.Assign(StudentList.createStudent("Kristen", "Kristinson"));
            Cohort30.Assign(StudentList.createStudent("Loshanna", "Loshannason"));
            Cohort30.Assign(StudentList.createStudent("Tre", "Treson"));
            Cohort30.Assign(StudentList.createStudent("Overachieving", "Asshat"));

            ExerciseList.createExercise("OverlyExcited", "Javascript");
            ExerciseList.createExercise("SolarSystem", "Javascript");
            ExerciseList.createExercise("CarLot", "Javascript");
            ExerciseList.createExercise("DynamicCards", "Javascript");

            Cohort30.Assign(InstructorList.createInstructor("Idont", "Remember"));
            Cohort30.Assign(InstructorList.createInstructor("Who", "Taught"));
            Cohort30.Assign(InstructorList.createInstructor("Cohort", "Thirty"));

            //note to self: never do it like this again. Just wanted to see if I could keep it all straight in my head long enough to type out working code.
            //for each student wher student cohort is cohort 30, iterate through a list of exercies that are of the javascript langauge and assign those to the student.
            StudentList.getAll().Where(student => student.Cohort() == Cohort30.Name()).ToList().ForEach(student => ExerciseList.getAll().Where(exercise => exercise.Language() == "Javascript").ToList().ForEach(exercise => student.Assign(exercise)));

            Student Overachiever = StudentList.getAll().First(Student => Student.Name() == "Overachieving Asshat");

            ExerciseList.getAll().Where(exercise => exercise.Language() == "C#").ToList().ForEach(exercise => Overachiever.Assign(exercise));

            Cohort30.Assign(StudentList.createStudent("Lazy", "Asshole"));

            Console.WriteLine("All javascript exercises");
            //For all exercises where javascript is the language, write out the name of the exercise and its langauge.
            ExerciseList.getAll().Where(exercise => exercise.Language() == "Javascript").ToList().ForEach(exercise => Console.WriteLine($"{exercise.Name()} is in {exercise.Language()}"));
            Console.WriteLine("----------------------");

            Console.WriteLine("All students in Cohort 30");
            StudentList.getAll().Where(student => student.Cohort() == Cohort30.Name()).ToList().ForEach(student => Console.WriteLine($"{student.Name()} is in {student.Cohort()}"));
            Console.WriteLine("----------------------");

            Console.WriteLine("All Instructors in Cohort 30");
            InstructorList.getAll().Where(instructor => instructor.Cohort() == Cohort30.Name()).ToList().ForEach(instructor => Console.WriteLine($"{instructor.Name()} is in {instructor.Cohort()}"));
            Console.WriteLine("----------------------");
            Console.WriteLine("All students sorted by LastName");
            StudentList.getAll().OrderBy(student => student.LastName()).ToList().ForEach(student => Console.WriteLine($"{student.LastName()}, {student.FirstName()}"));

            Console.WriteLine("----------------------");
            Console.WriteLine("All students working on 0 exercises:");
            StudentList.getAll().Where(student => student.ExerciseList().Count == 0).ToList().ForEach(student => Console.WriteLine(student.Name()));

            Console.WriteLine("----------------------");
            Console.WriteLine("The student working on the most exercises:");
            int MaxExercises = StudentList.getAll().Select(student => student.ExerciseList().Count).Max();

            Console.WriteLine(StudentList.getAll().First(student => student.ExerciseList().Count == MaxExercises).Name());

            Console.WriteLine("----------------------");
            Console.WriteLine("The number of students in each cohort:");
            IEnumerable <EnrollmentReport> enrollmentReports = CohortList.AllCohorts().Select(cohort => new EnrollmentReport {
                CohortName   = cohort.Name(),
                StudentCount = StudentList.getAll().Where(student => student.Cohort() == cohort.Name()).ToList().Count
            });

            foreach (EnrollmentReport report in enrollmentReports)
            {
                Console.WriteLine($"{report.CohortName} has {report.StudentCount} students.");
            }
        }
Пример #3
0
        static void Main(string[] args)

        {
            var studentExercise = new Exercise()
            {
                Name     = "Student Exercise",
                Language = "C#"
            };

            var jsExercise = new Exercise()
            {
                Name     = "Chicken Monkey",
                Language = "JavaScript"
            };

            var journal = new Exercise()
            {
                Name     = "Journal",
                Language = "HTML"
            };

            var sqlExercise = new Exercise()
            {
                Name     = "Data",
                Language = "SQL"
            };

            var c30 = new Cohort()
            {
                CohortName = "Day Cohort 30"
            };
            var c31 = new Cohort()
            {
                CohortName = "Day Cohort 31"
            };
            var c32 = new Cohort()
            {
                CohortName = "Day Cohort 32"
            };
            var c33 = new Cohort()
            {
                CohortName = "Day Cohort 33"
            };

            var adam = new Instructor
            {
                FirstName   = "Adam",
                LastName    = "Sheaffer",
                SlackHandle = "Teachers Pet",
                Specialty   = "Hacking"
            };
            var brian = new Instructor
            {
                FirstName   = "Brian",
                LastName    = "Highfive",
                SlackHandle = "Rocker",
                Specialty   = "High Five"
            };
            var jisie = new Instructor
            {
                FirstName   = "Jisie",
                LastName    = "David",
                SlackHandle = "Bigboss",
                Specialty   = "Hacking"
            };
            var bill = new Instructor
            {
                FirstName   = "Bill",
                LastName    = "Bob",
                SlackHandle = "Red neck",
                Specialty   = "Shooting guns"
            };

            c32.addInstructorToCohort(brian);
            c32.addInstructorToCohort(bill);
            c32.addInstructorToCohort(jisie);

            var jake = new Student
            {
                FirstName   = "Jake",
                LastName    = "Smith",
                SlackHandle = "JSmith"
            };

            var logan = new Student
            {
                FirstName   = "Logan",
                LastName    = "Baxter",
                SlackHandle = "Baxter"
            };

            var dek = new Student
            {
                FirstName   = "Dek",
                LastName    = "America",
                SlackHandle = "DekYea"
            };

            c32.addStudentToCohort(dek);
            c32.addStudentToCohort(logan);
            c32.addStudentToCohort(jake);

            jisie.AssignExercise(logan, studentExercise);
            jisie.AssignExercise(logan, jsExercise);
            adam.AssignExercise(dek, studentExercise);
            adam.AssignExercise(dek, jsExercise);
            brian.AssignExercise(jake, studentExercise);
            brian.AssignExercise(jake, jsExercise);

            var AllStudents = new List <Student>();

            {
                AllStudents.Add(logan);
                AllStudents.Add(dek);
                AllStudents.Add(jake);
            };

            var AllInstructors = new List <Instructor>();

            {
                AllInstructors.Add(adam);
                AllInstructors.Add(brian);
                AllInstructors.Add(jisie);
            };

            var AllExercises = new List <Exercise>();

            {
                AllExercises.Add(jsExercise);
                AllExercises.Add(journal);
                AllExercises.Add(studentExercise);
                AllExercises.Add(sqlExercise);
            };

            var AllCohorts = new List <Cohort>();

            {
                AllCohorts.Add(c30);
                AllCohorts.Add(c31);
                AllCohorts.Add(c32);
                AllCohorts.Add(c33);
            };

            List <Exercise> JSExercise = (from exercise in AllExercises
                                          where exercise.Language == "JavaScript"
                                          select exercise).ToList();

            foreach (Exercise exer in JSExercise)
            {
                Console.WriteLine($"List of JS exercises: {exer.Name}");
            }

            List <Student> studentsInChorty = (from Student in AllStudents
                                               where Student.cohort)
        }
Пример #4
0
        static void Main(string[] args)
        {
            Exercise ChickenMonkey = new Exercise();

            ChickenMonkey.Name     = "ChickenMonkey";
            ChickenMonkey.Language = "JavaScript";

            Exercise FavoriteThings = new Exercise();

            FavoriteThings.Name     = "Favorite Things";
            FavoriteThings.Language = "JavaScript";

            Exercise Kennel = new Exercise();

            Kennel.Name     = "Kennel";
            Kennel.Language = "React";

            Exercise CssSelectors = new Exercise();

            CssSelectors.Name     = "CSS Selectors";
            CssSelectors.Language = "CSS";

            Cohort c33 = new Cohort();

            c33.Name = "Cohort 33";

            Cohort c34 = new Cohort();

            c34.Name = "Cohort 34";

            Cohort c35 = new Cohort();

            c35.Name = "Cohort 35";

            Student student1 = new Student();

            student1.FirstName   = "Harry";
            student1.LastName    = "Potter";
            student1.SlackHandle = "TheQuiddichBitch";
            student1.Cohort      = c33;

            Student student2 = new Student();

            student2.FirstName   = "Ron";
            student2.LastName    = "Weasley";
            student2.SlackHandle = "SlugMan";
            student2.Cohort      = c34;

            Student student3 = new Student();

            student3.FirstName   = "Hermione";
            student3.LastName    = "Granger";
            student3.SlackHandle = "ThatPunchFeltGood";
            student3.Cohort      = c35;

            Student student4 = new Student();

            student4.FirstName   = "Draco";
            student4.LastName    = "Malfoy";
            student4.SlackHandle = "MyFatherWillHearAboutThis";
            student4.Cohort      = c33;

            Student student5 = new Student();

            student5.FirstName   = "Neville";
            student5.LastName    = "Longbottom";
            student5.SlackHandle = "ILongForYourBottom";
            student5.Cohort      = c35;

            Instructor instructor1 = new Instructor();

            instructor1.FirstName   = "Severus";
            instructor1.LastName    = "Snape";
            instructor1.SlackHandle = "TheHalfBloodPrince";
            instructor1.Specialty   = "Potions";
            instructor1.Cohort      = c34;

            Instructor instructor2 = new Instructor();

            instructor2.FirstName   = "Filius";
            instructor2.LastName    = "Flitwick";
            instructor2.SlackHandle = "OneCharmingDude";
            instructor2.Specialty   = "Charms";
            instructor2.Cohort      = c33;

            Instructor instructor3 = new Instructor();

            instructor3.FirstName   = "Minerva";
            instructor3.LastName    = "McGonagall";
            instructor3.SlackHandle = "ShouldITurnYouIntoAPocketwatch";
            instructor3.Specialty   = "Transfiguration";
            instructor3.Cohort      = c35;

            instructor1.AssignStudentAnExercise(student1, ChickenMonkey);
            instructor2.AssignStudentAnExercise(student1, CssSelectors);
            instructor1.AssignStudentAnExercise(student1, Kennel);
            instructor3.AssignStudentAnExercise(student2, ChickenMonkey);
            instructor2.AssignStudentAnExercise(student3, CssSelectors);
            instructor3.AssignStudentAnExercise(student3, FavoriteThings);
            instructor1.AssignStudentAnExercise(student4, Kennel);
            instructor3.AssignStudentAnExercise(student4, FavoriteThings);

            List <Student> allStudents = new List <Student>()
            {
                student1, student2, student3, student4, student5
            };

            List <Exercise> allExercises = new List <Exercise>()
            {
                ChickenMonkey, CssSelectors, Kennel, FavoriteThings
            };

            List <Instructor> allInstructors = new List <Instructor>()
            {
                instructor1, instructor2, instructor3
            };

            List <Cohort> allCohorts = new List <Cohort>()
            {
                c33, c34, c35
            };

            foreach (Exercise exercise in allExercises)
            {
                Console.WriteLine($"Students Working on {exercise.Name}:");
                foreach (Student student in allStudents)
                {
                    if (student.ExerciseList.Exists(studentExercise => exercise == studentExercise))
                    {
                        Console.WriteLine($"{student.FirstName} {student.LastName}");
                    }
                }
                Console.WriteLine("-----------------------------------");
            }

            // ------ PART 2 ------

            // 1. List exercises for the JavaScript language by using the Where() LINQ method.
            List <Exercise> javascriptExercises = allExercises.Where(e => e.Language == "JavaScript").ToList();
            // 2. List students in a particular cohort by using the Where() LINQ method.
            List <Student> studentsInC34 = allStudents.Where(s => s.Cohort == c34).ToList();
            // 3. List instructors in a particular cohort by using the Where() LINQ method.
            List <Instructor> instructorsInC33 = allInstructors.Where(i => i.Cohort == c33).ToList();
            // 4. Sort the students by their last name.
            List <Student> sortedStudents = allStudents.OrderBy(s => s.LastName).ToList();
            // 5. Display any students that aren't working on any exercises.
            List <Student> studentsNotWorkingOnExercises = allStudents.Where(s => s.ExerciseList.Count() == 0).ToList();
            // 6. Which student is working on the most exercises? Make sure one of your students has more exercises than the others.
            Student studentWorkingOnTheMostExercises = allStudents.OrderByDescending(s => s.ExerciseList.Count()).ToList()[0];
            // 7. How many students in each cohort?
            var studentsInEachCohort = allStudents.GroupBy(s => s.Cohort).Select(group => $"{group.Key.Name} has {group.Count()} students");
        }
Пример #5
0
        static void Main(string[] args)
        {
            var repo = new Repository();

            //Query the database for all the Exercises.
            List <Exercise> allExercises = repo.GetAllExercises();

            Console.WriteLine("All Exercises");
            foreach (var e in allExercises)
            {
                Console.WriteLine(e.Name);
            }
            Pause();

            //Find all the exercises in the database where the language is Python.
            List <Exercise> pythonExercises = repo.GetAllExercisesByLanguage("Python");

            Console.WriteLine("Python Exercises:");
            foreach (var e in pythonExercises)
            {
                Console.WriteLine(e.Name);
            }
            Pause();

            //Insert a new exercise into the database.
            repo.AddNewExercise("Student Exercises", "C#");
            List <Exercise> allExercisesWithNew = repo.GetAllExercises();

            Console.WriteLine("All Exercises with new one:");
            foreach (var e in allExercisesWithNew)
            {
                Console.WriteLine(e.Name);
            }
            Pause();

            //Find all instructors in the database. Include each instructor's cohort.
            List <Instructor> allInstructors = repo.GetAllInstructorsWithCohort();

            Console.WriteLine("All Instructors:");
            foreach (var i in allInstructors)
            {
                Console.WriteLine($"{i.FirstName} {i.LastName}, Cohort {i.Cohort.Name}");
            }
            Pause();

            //Insert a new instructor into the database.Assign the instructor to an existing cohort.

            var newInstructor = new Instructor
            {
                FirstName   = "Kimmy",
                LastName    = "Bird",
                SlackHandle = "pandadance",
                CohortId    = 1
            };

            repo.AddInstructor(newInstructor);
            List <Instructor> allInstructorsUpdated = repo.GetAllInstructorsWithCohort();

            Console.WriteLine("New Instructor added");
            Console.WriteLine("All Instructors:");
            foreach (var i in allInstructorsUpdated)
            {
                Console.WriteLine($"{i.FirstName} {i.LastName}, Cohort {i.Cohort.Name}");
            }
            Pause();

            //Assign an existing exercise to an existing student.
            repo.AssignExerciseToStudent(1, 4);
            Student student          = repo.GetStudents().First(x => x.Id == 1);
            var     studentExercises = repo.GetStudentExercises(1);

            Console.WriteLine($"New exercise assigned to {student.FirstName}");
            Console.WriteLine($"{student.FirstName}'s exercises:");
            foreach (var e in studentExercises)
            {
                Console.WriteLine($"{e.Name}, {e.Language}");
            }
        }
Пример #6
0
        ///  The Main method is the starting point for a .net application.
        static void Main(string[] args)
        {
            /// Create an instance of the Repository class in order to use its methods to interact with the database.
            Repository             repository       = new Repository();
            List <Exercise>        exercises        = repository.GetAllExercises();
            List <Student>         students         = repository.GetAllStudentsWithCohorts();
            List <StudentExercise> studentExercises = repository.GetAllStudentExercises();
            List <Instructor>      instructors      = repository.GetAllInstructorsWithCohorts();

            PrintExerciseReport("All Exercises", exercises);

            Pause();

            // Find all the exercises in the database where the language is JavaScript.
            IEnumerable <Exercise> JsExercises = exercises.Where(e => e.ExerciseLanguage == "Javascript");

            PrintExerciseReport("Javascript Exercises", JsExercises.ToList());

            Pause();


            // Insert a new exercise into the database.
            Exercise adoNetSql = new Exercise {
                ExerciseName = "Using ADO.NET and SQL", ExerciseLanguage = "C#"
            };

            // Pass the exercise object as an argument to the repository's AddExercise() method.
            repository.AddExercise(adoNetSql);

            exercises = repository.GetAllExercises();
            PrintExerciseReport("All Departments after adding new C# exercise", exercises);

            Pause();

            // Find all instructors in the database. Include each instructor's cohort.
            PrintInstructorReport("All Instructors", instructors);

            Pause();

            // Insert a new instructor into the database. Assign the instructor to an existing cohort.
            Instructor brenda = new Instructor {
                FirstName = "Brenda", LastName = "Long", Slack = "brenda", CohortId = 1
            };

            // Pass the exercise object as an argument to the repository's AddExercise() method.
            repository.AddInstructor(brenda);
            instructors = repository.GetAllInstructorsWithCohorts();
            PrintInstructorReport("All Instructors after adding new instructor", instructors);
            Pause();

            PrintStudentExerciseReport("All Student Exercises", studentExercises);
            Pause();

            // Assign an existing exercise to an existing student.
            StudentExercise newAssignment = new StudentExercise {
                StudentId = 9, ExerciseId = 1
            };

            repository.AddExerciseToStudent(newAssignment);
            studentExercises = repository.GetAllStudentExercises();
            PrintStudentExerciseReport("All Student Exercises after assigning a new one", studentExercises);
            Pause();
        }
Пример #7
0
        static void Main(string[] args)
        {
            Exercise Exercise1 = new Exercise()
            {
                Name     = "Object practice",
                Language = "JavaScript"
            };
            Exercise Exercise2 = new Exercise()
            {
                Name     = "Array Methods",
                Language = "JavaScript"
            };
            Exercise Exercise3 = new Exercise()
            {
                Name     = "LINQ",
                Language = "C#"
            };
            Exercise Exercise4 = new Exercise()
            {
                Name     = "Types",
                Language = "C#"
            };

            Cohort Day32 = new Cohort()
            {
                CohortName = "Cohort 32"
            };
            Cohort Day33 = new Cohort()
            {
                CohortName = "Cohort 33"
            };
            Cohort Day34 = new Cohort()
            {
                CohortName = "Cohort 34"
            };

            Student Deep = new Student()
            {
                FirstName   = "Deep",
                LastName    = "Patel",
                SlackHandle = "@ThePatel",
                Cohort      = 32
            };

            Student Ellie = new Student()
            {
                FirstName   = "Ellie",
                LastName    = "Ash",
                SlackHandle = "@TheAsh",
                Cohort      = 33
            };
            Student Janki = new Student()
            {
                FirstName   = "Janki",
                LastName    = "Patel",
                SlackHandle = "@TheJanki",
                Cohort      = 34
            };

            Student Kishan = new Student()
            {
                FirstName   = "Kishan",
                LastName    = "Bant",
                SlackHandle = "@TheBant",
                Cohort      = 34
            };
            Student Dan = new Student()
            {
                FirstName   = "Dan",
                LastName    = "Storm",
                SlackHandle = "@TheStorm",
                Cohort      = 34
            };

            Day32.AddStudent(Deep);
            Day32.AddStudent(Ellie);
            Day32.AddStudent(Janki);
            Day32.AddStudent(Kishan);

            Instructor Adam = new Instructor()
            {
                FirstName   = "Adam",
                LastName    = "Sheaffer",
                SlackHandle = "@TheSheaffer",
                Cohort      = 33
            };
            Instructor Kristen = new Instructor
            {
                FirstName   = "Kristen",
                LastName    = "Norris",
                SlackHandle = "@TheNorris",
                Cohort      = 31
            };
            Instructor Jisie = new Instructor()
            {
                FirstName   = "Jisie",
                LastName    = "David",
                SlackHandle = "@TheDavid",
                Cohort      = 32
            };

            Day32.AddInstructor(Adam);
            Day32.AddInstructor(Kristen);
            Day32.AddInstructor(Jisie);

            Adam.AssignStudents(Deep, Exercise1);
            Adam.AssignStudents(Deep, Exercise2);

            Kristen.AssignStudents(Ellie, Exercise3);
            Kristen.AssignStudents(Ellie, Exercise4);

            Jisie.AssignStudents(Janki, Exercise2);
            Jisie.AssignStudents(Janki, Exercise4);

            Adam.AssignStudents(Kishan, Exercise1);
            Adam.AssignStudents(Janki, Exercise3);

            List <Cohort> cohorts = new List <Cohort>();

            cohorts.Add(Day32);
            cohorts.Add(Day33);
            cohorts.Add(Day34);

            List <Instructor> instructors = new List <Instructor>();

            instructors.Add(Adam);
            instructors.Add(Kristen);
            instructors.Add(Jisie);

            List <Student> students = new List <Student>();

            students.Add(Deep);
            students.Add(Ellie);
            students.Add(Janki);
            students.Add(Kishan);
            students.Add(Dan);

            List <Exercise> exercises = new List <Exercise>();

            exercises.Add(Exercise1);
            exercises.Add(Exercise2);
            exercises.Add(Exercise3);
            exercises.Add(Exercise4);



            foreach (Student student in students)
            {
                Console.WriteLine($"Student: {student.FirstName}");
                foreach (Exercise exercise in student.Exercises)
                {
                    Console.WriteLine($"Exercise: {exercise.Name}");
                }
            }
            Console.WriteLine("------------------------------");

            var jsExercises = (from exercise in exercises
                               where exercise.Language == "JavaScript"
                               select exercise);

            jsExercises.ToList().ForEach(ex => Console.WriteLine($"list of JS exercises: {ex.Name}"));
            Console.WriteLine("------------------------------");

            var studentsInCohort = (from student in students
                                    where student.Cohort == 34
                                    select student);

            studentsInCohort.ToList().ForEach(student => Console.WriteLine($"Cohort 34 members: {student.FirstName}{student.LastName}"));
            Console.WriteLine("------------------------------");

            var instructorsInCohort = (from instructor in instructors
                                       where instructor.Cohort == 33
                                       select instructor);

            instructorsInCohort.ToList().ForEach(instructor => Console.WriteLine($"Cohort 33 Instructor: {instructor.FirstName} {instructor.LastName}"));
            Console.WriteLine("------------------------------");

            var studentsByLast = students.OrderBy(student => student.LastName).ToList();

            Console.WriteLine("Students by last name:");
            foreach (Student student in students)
            {
                Console.WriteLine($"{student.LastName} {student.FirstName}");
            }
            Console.WriteLine("------------------------------");

            var notWorkingStudent = (from student in students
                                     where student.Exercises.Count == 0
                                     select student);

            notWorkingStudent.ToList().ForEach(student => Console.WriteLine($"Students not working on any exercises: {student.FirstName} {student.LastName}"));
            Console.WriteLine("------------------------------");

            var mostExercises = students.OrderByDescending(student => student.Exercises.Count()).Take(1);

            Console.WriteLine("Student with the most exercises assigned: ");
            foreach (Student student in mostExercises)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName}");
            }
            Console.WriteLine("------------------------------");

            foreach (var cohort in cohorts)
            {
                Console.WriteLine($"{cohort.CohortName} has {cohort.Students.Count()} students");
            }
            Console.WriteLine("------------------------------");
        }
Пример #8
0
 public void AddInstructor(Instructor name)
 {
     instructors.Add(name);
     name.cohort = this.name;
 }
Пример #9
0
        static void Main(string[] args)
        {
            // create the exercises
            Exercise nutshell    = new Exercise("nutshell", "React");
            Exercise holidayRoad = new Exercise("Holiday Road", "C#");
            Exercise fitted      = new Exercise("Fitted", "React");
            Exercise bangazon    = new Exercise("Bangazon", "C#");

            //create the cohorts
            Cohort cohort37 = new Cohort("Cohort 37");
            Cohort cohort36 = new Cohort("Cohort 36");
            Cohort cohort35 = new Cohort("Cohort 35");

            //create the students
            Student kevin   = new Student("Kevin", "Penny", "kpen3", cohort36);
            Student james   = new Student("James", "Nitz", "jitzynitzy", cohort37);
            Student audrey  = new Student("Audrey", "Borgra", "BigBrainBorgra", cohort36);
            Student namita  = new Student("Namita", "Manohar", "namitabannana", cohort37);
            Student jansen  = new Student("Jansen", "Vanderspuy", "simplyJantastic", cohort35);
            Student garrett = new Student("Garrett", "Freshwater", "gFresh", cohort36);

            // create the instructors
            Instructor steve = new Instructor("Steve", "Brownlee", "choortlehort", cohort37, "dad jokes");
            Instructor mo    = new Instructor("Mo", "Silvera", "MoCodeLessProblems", cohort36, "Cheesecakes");
            Instructor leah  = new Instructor("Leah", "Hoeffling", "LeahLemurLady", cohort35, "petting lemurs");

            // assign the students to cohorts
            cohort35.AddStudent(jansen);
            cohort36.AddStudent(kevin);
            cohort36.AddStudent(audrey);
            cohort36.AddStudent(garrett);
            cohort37.AddStudent(james);
            cohort37.AddStudent(namita);

            // assign instructors to cohorts
            cohort35.AddInstructor(leah);
            cohort36.AddInstructor(mo);
            cohort37.AddInstructor(steve);

            // assing exercises to students
            mo.AddExercise(kevin, fitted);
            mo.AddExercise(kevin, nutshell);
            mo.AddExercise(audrey, holidayRoad);
            mo.AddExercise(audrey, fitted);
            leah.AddExercise(jansen, nutshell);
            leah.AddExercise(jansen, bangazon);
            steve.AddExercise(namita, nutshell);
            steve.AddExercise(namita, holidayRoad);
            steve.AddExercise(james, nutshell);
            steve.AddExercise(james, bangazon);
            steve.AddExercise(james, fitted);

            // create list of students
            var studentsList = new List <Student>();

            studentsList.Add(kevin);
            studentsList.Add(namita);
            studentsList.Add(audrey);
            studentsList.Add(james);
            studentsList.Add(jansen);
            studentsList.Add(garrett);

            // create list of exercises
            var exercisesList = new List <Exercise>();

            exercisesList.Add(nutshell);
            exercisesList.Add(fitted);
            exercisesList.Add(holidayRoad);
            exercisesList.Add(bangazon);

            foreach (Exercise exercise in exercisesList)
            {
                Console.WriteLine($"--- {exercise.Name.ToUpper()} ---");
                foreach (Student student in studentsList)
                {
                    foreach (Exercise singleExercise in student.Exercises)
                    {
                        if (singleExercise.Name == exercise.Name)
                        {
                            Console.WriteLine($@"{student.FirstName} {student.LastName}");
                            Console.WriteLine(" ");
                        }
                    }
                }
            }

            var allReactExercises = exercisesList.Where(langExercise =>
            {
                return(langExercise.Language == "React");
            });

            foreach (var langExercise in allReactExercises)
            {
                Console.WriteLine(langExercise.Name);
            }

            var studentsOrderedByLastName = studentsList.OrderByDescending(student =>
            {
                return(student.LastName);
            });

            foreach (var student in studentsOrderedByLastName)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName}");
            }

            var studentsWithNoExercises = studentsOrderedByLastName.Where(student =>
            {
                int exercisesCount = student.Exercises.Count;

                return(exercisesCount == 0);
            });

            Console.WriteLine($"----These students are not working on any exercises----");

            foreach (var student in studentsWithNoExercises)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName}");
            }

            var studentWithMostExercises = studentsList.OrderByDescending(student =>
            {
                return(student.Exercises.Count);
            }).FirstOrDefault();

            var groups = studentsList.GroupBy(student => student.Cohort.Name);

            foreach (var group in groups)
            {
                Console.WriteLine($"There are {group.Count()} students in {group.Key}");
            }
        }
Пример #10
0
        static void Main()
        {
            /* Create 4, or more, exercises.
             * Create 3, or more, cohorts.
             * Create 4, or more, students and assign them to one of the cohorts.
             * Create 3, or more, instructors and assign them to one of the cohorts.
             * Have each instructor assign 2 exercises to each of the students. */

            Exercise Journal     = new Exercise("Student Journal", "Javascript");
            Exercise KandyKorner = new Exercise("Kandy Korner", "React")
            {
            };
            Exercise CarLot   = new Exercise("Car Lot", "C#");
            Exercise Personal = new Exercise("Personal Website", "HTML");

            Cohort thirty       = new Cohort("Cohort 30");
            Cohort twentynine   = new Cohort("Cohort 29");
            Cohort eveningeight = new Cohort("Evening 8");

            Student pEris     = new Student("Panya Gwynn-Eris", "naienko");
            Student sRainault = new Student("Summer Rainault", "firechild");
            Student bAllen    = new Student("Bartholomew Allen", "theflash");
            Student kDubhglas = new Student("Kieran Dubhglas", "eolascraicte");

            Instructor sBrownlee = new Instructor("Steve Brownlee", "chortlehoort");
            Instructor sStCyr    = new Instructor("Sebastien StCyr", "elementalist");
            Instructor eThawne   = new Instructor("Eobard Thawne", "reverseflash");

            thirty.AddStudents(new List <Student> {
                sRainault, bAllen
            }, thirty);
            thirty.AddInstructors(eThawne, thirty);

            eveningeight.AddStudents(kDubhglas, eveningeight);
            eveningeight.AddInstructors(sBrownlee, eveningeight);

            twentynine.AddStudents(pEris, twentynine);
            twentynine.AddInstructors(sStCyr, twentynine);

            sBrownlee.AssignExercise(Personal, kDubhglas);
            sStCyr.AssignExercise(Journal, pEris);
            eThawne.AssignExercise(KandyKorner, new List <Student> {
                sRainault, bAllen
            });

            eThawne.AssignExercise(CarLot, sRainault);
            eThawne.AssignExercise(Journal, bAllen);

            sStCyr.AssignExercise(Personal, pEris);

            sBrownlee.AssignExercise(Journal, kDubhglas);

            Console.WriteLine(thirty);
            Console.WriteLine(twentynine);
            Console.WriteLine(eveningeight);

            List <Student> students = new List <Student>()
            {
                pEris, bAllen, sRainault, kDubhglas
            };
            List <Exercise> exercises = new List <Exercise>()
            {
                Journal, CarLot, KandyKorner, Personal
            };
            List <Instructor> instructors = new List <Instructor>()
            {
                sBrownlee, eThawne, sStCyr
            };
            List <Cohort> cohorts = new List <Cohort>()
            {
                eveningeight, twentynine, thirty
            };

            // List exercises for the JavaScript language by using the Where() LINQ method.
            var javascriptExercises = exercises.Where(e => e.Language == "Javascript");

            Console.WriteLine("Exercises in Javascript");
            foreach (var item in javascriptExercises)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine(" ");
            //List students in a particular cohort by using the Where() LINQ method.
            var cohortThirtyStudents = students.Where(s => s._cohort == thirty);

            Console.WriteLine("Cohort Thirty students");
            foreach (var item in cohortThirtyStudents)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine(" ");
            //List instructors in a particular cohort by using the Where() LINQ method.
            var cohortTwentynineInstructors = instructors.Where(i => i._cohort == twentynine);

            Console.WriteLine("Cohort Twenty Nine Instructors");
            foreach (var item in cohortTwentynineInstructors)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine(" ");
            //Sort the students by their last name.
            IEnumerable <Student> byLastName = from student in students
                                               orderby student._lastname ascending
                                               select student;

            Console.WriteLine("Sort by last name");
            foreach (var item in byLastName)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine(" ");
            //Display any students that aren't working on any exercises (Make sure one of your student instances don't have any exercises. Create a new student if you need to.)
            Student tMaclyr = new Student("Teleri MacLyr", "selkiegirl");

            students.Add(tMaclyr);
            IEnumerable <Student> boredStudent = from student in students
                                                 where student.Exercises.Count == 0
                                                 select student;

            Console.WriteLine("Students who have no exercises");
            foreach (var item in boredStudent)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine(" ");
            //Which student is working on the most exercises? Make sure one of your students has more exercises than the others.
            eThawne.AssignExercise(Personal, sRainault);
            IEnumerable <Student> starStudents = from student in students
                                                 orderby student.Exercises.Count descending
                                                 select student;

            Console.WriteLine("The student who has the most exercises");
            Console.WriteLine(starStudents.First());

            Console.WriteLine(" ");
            //How many students in each cohort?
            List <StudentsInCohort> studentsPerCohort = (
                from student in students
                group student by student._cohort into cohortGroup
                select new StudentsInCohort {
                cohortName = cohortGroup.Key,
                cohortCount = cohortGroup.Count()
            }
                ).ToList();

            foreach (StudentsInCohort entry in studentsPerCohort)
            {
                try{
                    Console.WriteLine($"{entry.cohortName.Name} has {entry.cohortCount} students in it.");
                }
                catch (NullReferenceException) {
                    Console.WriteLine($"There are unassigned students!");
                }
            }
        }
Пример #11
0
        static void Main(string[] args)
        {

            // GET ALL EXERCISES
            ExercisesController exercisesController = new ExercisesController();

            var exercises = exercisesController.GetAllExercises();

            exercises.ForEach(exercise =>
            {
                Console.WriteLine($"{exercise.Id}: {exercise.ExerciseName} -- {exercise.ExerciseLanguage}");
                Console.WriteLine(" ");
            });

            Pause();

            // Find all the exercises in the database where the language is JavaScript.
            var selectExercises = exercisesController.GetExerciseByLanguage("C#");

            selectExercises.ForEach(exercise =>
            {
                Console.WriteLine($"{exercise.Id}: {exercise.ExerciseName} -- {exercise.ExerciseLanguage}");
                Console.WriteLine(" ");
            });

            Pause();

            // Insert a new exercise into the database.
            Exercise exerciseToAdd = new Exercise
            {
                ExerciseName = "Personal Website",
                ExerciseLanguage = "ReactJS"
            };

            //exercisesController.AddExercise(exerciseToAdd);
            Pause();

            // Insert a new instructor into the database. Assign the instructor to an existing cohort.
            InstructorsController instructorsController = new InstructorsController();
            Instructor instructorToAdd = new Instructor
            {
                FirstName = "Todd",
                LastName = "Packer",
                SlackHandle = "@tpDaddy",
                CohortId = 2,
                Specialty = "Hitting on Women"
            };

            instructorsController.AddInstructor(instructorToAdd);
            Pause();

            // Assign an existing exercise to an existing student.
            AssignmentsController assignmentsController = new AssignmentsController();
            Assignment assignmentToAssign = new Assignment
            {
                StudentId = 1,
                InstructorId = 2,
                ExerciseId = 3
            };

            assignmentsController.AssignExercise(assignmentToAssign);
            Pause();

            // Find all the students in the database. Include each student's cohort AND each student's list of exercises.
            StudentsController studentsController = new StudentsController();
            var students = studentsController.GetAllStudents();

            // HOW TO ONLY SHOW STUDENTS ONCE???
            students.ForEach(student =>
            {
                
                Console.WriteLine($"{student.Id}: {student.FirstName}{student.LastName} [{student.cohort.Title}] -- ");
                Console.WriteLine("Exercises:");
                exercises.ForEach(ex =>
                {
                    Console.WriteLine($"{ex.ExerciseName} -- {ex.ExerciseLanguage}");
                });
            });

            Pause();
        }
Пример #12
0
        static void Main(string[] args)
        {
            // Create 4, or more, exercises.
            // Exercise ChickenMonkey = new Exercise ("Chicken Monkey", "JavaScript");
            // Exercise CssSelectors = new Exercise ("Advanced CSS Selectors", "CSS");
            // Exercise ReactComponents = new Exercise ("React Components", "React");
            // Exercise YellowBrickRoad = new Exercise ("Yellow Brick Road", "HTML");

            Exercise ChickenMonkey = new Exercise()
            {
                Name             = "Chicken Monkey",
                ExerciseLanguage = "JavaScript"
            };
            Exercise CssSelectors = new Exercise()
            {
                Name             = "Advanced CSS Selectors",
                ExerciseLanguage = "CSS"
            };
            Exercise ReactComponents = new Exercise()
            {
                Name             = "React Components",
                ExerciseLanguage = "React"
            };
            Exercise YellowBrickRoad = new Exercise()
            {
                Name             = "Yellow Brick Road",
                ExerciseLanguage = "HTML"
            };

            // Create 3, or more, cohorts.
            Cohort C26 = new Cohort()
            {
                CohortName = "Day Cohort 26"
            };
            Cohort C27 = new Cohort()
            {
                CohortName = "Day Cohort 27"
            };
            Cohort C28 = new Cohort()
            {
                CohortName = "Day Cohort 28"
            };

            // Create 4, or more, students and assign them to one of the cohorts.
            Student Jonathan = new Student()
            {
                FirstName   = "Jonathan",
                LastName    = "Edwards",
                SlackHandle = "@Jonathan",
                Cohort      = C27
            };

            C27.StudentCollection.Add(Jonathan);

            Student Alejandro = new Student()
            {
                FirstName   = "Alejandro",
                LastName    = "Font",
                SlackHandle = "@Alejandro",
                Cohort      = C28
            };

            C28.StudentCollection.Add(Alejandro);

            Student Madi = new Student()
            {
                FirstName   = "Madi",
                LastName    = "Peper",
                SlackHandle = "@Madi",
                Cohort      = C27
            };

            C27.StudentCollection.Add(Madi);

            Student Streator = new Student()
            {
                FirstName   = "Streator",
                LastName    = "Ward",
                SlackHandle = "@Streator",
                Cohort      = C26
            };

            C26.StudentCollection.Add(Streator);

            Student Ricky = new Student()
            {
                FirstName   = "Ricky",
                LastName    = "Bruner",
                SlackHandle = "@ricky",
                Cohort      = C26
            };

            C26.StudentCollection.Add(Ricky);

            // Create 3, or more, instructors and assign them to one of the cohorts.
            Instructor Steve = new Instructor()
            {
                FirstName   = "Steve",
                LastName    = "Brownlee",
                SlackHandle = "@coach",
                Cohort      = C27
            };

            C27.InstructorCollection.Add(Steve);

            Instructor Meg = new Instructor()
            {
                FirstName   = "Meg",
                LastName    = "Ducharme",
                SlackHandle = "@meg",
                Cohort      = C26
            };;

            C26.InstructorCollection.Add(Meg);

            Instructor Kimmy = new Instructor()
            {
                FirstName   = "Kimmy",
                LastName    = "Bird",
                SlackHandle = "@kimmy",
                Cohort      = C28
            };;

            C28.InstructorCollection.Add(Kimmy);

            // Have each instructor assign 2 exercises to each of the students.
            Steve.AssignExercise(Jonathan, ChickenMonkey);
            Steve.AssignExercise(Jonathan, CssSelectors);
            Steve.AssignExercise(Jonathan, ReactComponents);

            Steve.AssignExercise(Madi, CssSelectors);
            Steve.AssignExercise(Madi, ReactComponents);

            Meg.AssignExercise(Streator, ChickenMonkey);
            Meg.AssignExercise(Streator, CssSelectors);

            Kimmy.AssignExercise(Alejandro, ReactComponents);
            Kimmy.AssignExercise(Alejandro, YellowBrickRoad);

            // Create a list of students. Add all of the student instances to it.
            List <Student> students = new List <Student> ()
            {
                Jonathan,
                Alejandro,
                Madi,
                Streator,
                Ricky
            };

            // Create a list of exercises.Add all of the exercise instances to it.
            List <Exercise> exercises = new List <Exercise> ()
            {
                ChickenMonkey,
                CssSelectors,
                ReactComponents,
                YellowBrickRoad
            };

            // Create a list of instructors. Add all of the instructor instances to it.
            List <Instructor> instructors = new List <Instructor> ()
            {
                Steve,
                Meg,
                Kimmy,
            };

            // Create a list of cohorts. Add all of the cohort instances to it.
            List <Cohort> cohorts = new List <Cohort> ()
            {
                C26,
                C27,
                C28
            };

            foreach (Student student in students)
            {
                string StudentName         = student.FirstName;
                string StudentExerciseList = "";
                int    count = 0;

                foreach (Exercise exer in student.ExerciseCollection)
                {
                    if (count == 0)
                    {
                        StudentExerciseList = $"{exer.Name} in {exer.ExerciseLanguage}";
                        count++;
                    }
                    else
                    {
                        StudentExerciseList = $"{exer.Name} in {exer.ExerciseLanguage} and {StudentExerciseList}.";
                        count++;
                    }
                }

                Console.WriteLine($"{StudentName} of {student.Cohort.CohortName} is working on {StudentExerciseList}");
            }

            // List exercises for the JavaScript language by using the Where() LINQ method.
            List <Exercise> JavaScriptExercises =
                (from js in exercises where js.ExerciseLanguage == "JavaScript"
                 select js).ToList();

            Console.WriteLine("----- JS Exercises -----");
            foreach (Exercise ex in JavaScriptExercises)
            {
                Console.WriteLine(ex.Name);
            }

            // List students in a particular cohort by using the Where() LINQ method.
            List <Student> C27Students =
                (from student in students where student.Cohort.CohortName == "Day Cohort 27"
                 select student).ToList();

            Console.WriteLine("----- Cohort 27 Students -----");
            foreach (Student stu in C27Students)
            {
                Console.WriteLine(stu.FirstName);
            }

            // List instructors in a particular cohort by using the Where() LINQ method.
            List <Instructor> C27Instructors =
                (from ins in instructors where ins.Cohort.CohortName == "Day Cohort 27"
                 select ins).ToList();

            Console.WriteLine("----- Cohort 27 Instructors -----");
            foreach (Instructor ins in C27Instructors)
            {
                Console.WriteLine(ins.FirstName);
            }

            // Sort the students by their last name.
            List <Student> StudentsByLastName =
                (from student in students orderby student.LastName select student).ToList();

            Console.WriteLine("----- Students By Last Name -----");
            foreach (Student stu in StudentsByLastName)
            {
                Console.WriteLine($"{stu.FirstName} {stu.LastName}");
            }

            // Display any students that aren't working on any exercises
            List <Student> StudentsWithNoWork =
                (from stu in students where stu.ExerciseCollection.Count == 0 select stu).ToList();

            Console.WriteLine("----- Students Not Working On Exercises -----");
            foreach (Student stu in StudentsWithNoWork)
            {
                Console.WriteLine($"{stu.FirstName}");
            }

            // Which student is working on the most exercises?
            List <Student> StudentWithMostWork =
                (from stu in students orderby stu.ExerciseCollection.Count descending select stu).ToList();

            Console.WriteLine("----- Student With Most Work -----");
            Console.WriteLine($"{StudentWithMostWork.First().FirstName} is the student with the most exercises");

            // How many students in each cohort?
            Console.WriteLine("----- How many students in each cohort? -----");
            foreach (Cohort cohort in cohorts)
            {
                Console.WriteLine($"{cohort.CohortName} has {cohort.StudentCollection.Count} students in it");
            }

            SqliteConnection db = DatabaseInterface.Connection;

            // Query the database for all the Exercises.
            List <Exercise> AllEx = db.Query <Exercise> (@"SELECT * FROM Exercise").ToList();

            Console.WriteLine($"There are {AllEx.Count} exercises");

            // Find all the exercises in the database where the language is JavaScript.
            List <Exercise> JavaScriptEx =
                db.Query <Exercise> (@"SELECT  *
                                FROM Exercise e
                                WHERE e.ExerciseLanguage = 'JavaScript'
                                ").ToList();

            Console.WriteLine($"There are {JavaScriptEx.Count} JS exercises");

            // Insert a new exercise into the database.
            // db.Execute(@"
            // INSERT INTO exercise (name, ExerciseLanguage) VALUES ('Planets', 'C#');
            // ");

            // Find all instructors in the database. Include each instructor's cohort.
            Console.WriteLine("-----All Instructors and their Cohorts-----");
            db.Query <Instructor, Cohort, Instructor> (@"
                                SELECT *
                                FROM instructor i
                                JOIN Cohort c ON c.Id = i.CohortId
                                ", (instructor, cohort) => {
                instructor.Cohort = cohort;
                return(instructor);
            })
            .ToList()
            .ForEach(ins => Console.WriteLine($"{ins.FirstName} is the instructor for {ins.Cohort.CohortName}"));

            // Insert a new instructor into the database. Assign the instructor to an existing cohort.
            // db.Execute(@"
            // INSERT INTO instructor
            // (FirstName, LastName, SlackHandle, CohortId)
            // VALUES
            // ('Jenna', 'Solis', '@jenna', '2')
            // ");

            // Assign an existing exercise to an existing student.
            // db.Execute (@"
            //     INSERT INTO StudentExercise
            //     (ExerciseId, StudentId)
            //     VALUES
            //     (1, 4)
            //     ");

            // Find all the students in the database.
            // Include each student's cohort AND each student's list of exercises.
        }
Пример #13
0
        static void Main(string[] args)
        {
            // create 4, or more exercise
            Exercise classExercise      = new Exercise("Class Exercise", "JavaScript", 1);
            Exercise dictionaryExercise = new Exercise("Dictionary List", "C#", 2);
            Exercise reactExercise      = new Exercise("React Exercise", "React", 3);
            Exercise capstone           = new Exercise("Capstone ", "Java", 4);
            Exercise jsonServer         = new Exercise("JsonServer Data ", "JavaScript", 5);
            Exercise journalEntries     = new Exercise("Journal Entries", "C#", 6);
            Exercise sylyingSheet       = new Exercise("Sylying Sheet", "React", 7);
            Exercise documentsModel     = new Exercise("Documents Model ", "Java", 8);


            // create 3 or more cohort
            Cohort c31 = new Cohort("Cohort 31", 31);
            Cohort c30 = new Cohort("Cohort 30", 30);
            Cohort c32 = new Cohort("Cohort 32", 32);
            Cohort c33 = new Cohort("Cohort 31", 31);

            //create 4 or more Students and assign them  to 1 assignment


            Student Tome   = new Student("Tom", "Hall", 0);
            Student Dek    = new Student("Dek", "Abdi", 1);
            Student Jameka = new Student("Jameka", "Echols", 1);
            Student Ali    = new Student("Ali", "Abdulle", 1);

            // slack handle
            Ali.Slackhandle    = "aliAbdule";
            Tome.Slackhandle   = "tomeHall";
            Jameka.Slackhandle = "jamekaEchols";
            Dek.Slackhandle    = "dekAbdi";


            //add to cohort
            Ali.Cohor    = c31;
            Tome.Cohor   = c30;
            Jameka.Cohor = c32;
            Dek.Cohor    = c31;

            //create instructors

            Instructor Jisi = new Instructor("Jisi", "David", "Teacher", 1);
            Instructor Andy = new Instructor("Andy", "Collin", "Play Book", 2);
            Instructor Leah = new Instructor("Leah", "Hoefling", "Correction", 3);

            //slack contact
            Leah.SlackHandle = "leahHoefling";
            Andy.SlackHandle = "andyCollin";
            Jisi.SlackHandle = "jisiDavid";

            // Have each Student assign 2 exercises to each student
            Jisi.AssignExercise(Dek, classExercise);
            Jisi.AssignExercise(Dek, dictionaryExercise);
            Andy.AssignExercise(Ali, capstone);
            Andy.AssignExercise(Ali, jsonServer);
            Leah.AssignExercise(Jameka, reactExercise);
            Leah.AssignExercise(Jameka, documentsModel);
            Jisi.AssignExercise(Tome, dictionaryExercise);
            Andy.AssignExercise(Tome, journalEntries);

            //create list of student
            List <Student> students = new List <Student>()
            {
                Ali, Dek, Tome, Jameka
            };
            //create list of exercise
            List <Exercise> exercises = new List <Exercise>()
            {
                documentsModel, journalEntries, documentsModel, reactExercise,
                jsonServer, capstone, classExercise, dictionaryExercise
            };

            foreach (Student student in students)
            {
                student.getFullNameAddExercise(student);
                Console.WriteLine(" ");
            }
        }
Пример #14
0
        static void Main(string[] args)
        {
            // Create 4, or more, exercises.
            Exercise exercise1 = new Exercise();

            exercise1.name     = "Learn HTML";
            exercise1.language = "HTML";

            Exercise exercise2 = new Exercise();

            exercise2.name     = "Learn CSS";
            exercise2.language = "CSS";

            Exercise exercise3 = new Exercise();

            exercise3.name     = "Learn JS";
            exercise3.language = "JavaScript";

            Exercise exercise4 = new Exercise();

            exercise4.name     = "Learn React";
            exercise4.language = "React";

            // Create 3, or more, cohorts.
            Cohort cohortA = new Cohort();

            cohortA.name = "Day 32";

            Cohort cohortB = new Cohort();

            cohortB.name = "Day 33";

            Cohort cohortC = new Cohort();

            cohortB.name = "Day 34";

            Cohort cohortD = new Cohort();

            cohortD.name = "Evening 9";

            // Create 4, or more, students
            Student student1 = new Student();

            student1.firstName   = "Josh";
            student1.lastName    = "Webb";
            student1.slackHandle = "@Josh";

            Student student2 = new Student();

            student2.firstName   = "Joe";
            student2.lastName    = "Smith";
            student2.slackHandle = "@Joe";

            Student student3 = new Student();

            student3.firstName   = "Jane";
            student3.lastName    = "Smith";
            student3.slackHandle = "@Jane";

            Student student4 = new Student();

            student4.firstName   = "Sally";
            student4.lastName    = "Jones";
            student4.slackHandle = "@Sally";

            // and assign students to one of the cohorts.
            cohortA.studentsInCohort.Add(student1);
            cohortB.studentsInCohort.Add(student2);
            cohortC.studentsInCohort.Add(student3);
            cohortD.studentsInCohort.Add(student4);

            // Create 3, or more, instructors
            Instructor instructor1 = new Instructor();

            instructor1.firstName   = "Adam";
            instructor1.lastName    = "Schaeffer";
            instructor1.slackHandle = "@Adam";

            Instructor instructor2 = new Instructor();

            instructor2.firstName   = "Jisie";
            instructor2.lastName    = "David";
            instructor2.slackHandle = "@Jisie";

            Instructor instructor3 = new Instructor();

            instructor3.firstName   = "Brenda";
            instructor3.lastName    = "Long";
            instructor3.slackHandle = "@Brenda";

            // assign instructor to one of the cohorts.
            cohortA.instructorsInCohort.Add(instructor1);
            cohortB.instructorsInCohort.Add(instructor2);
            cohortC.instructorsInCohort.Add(instructor3);

            // Have each instructor assign 2 exercises to each of the students.
            instructor1.assignExercise(student1, exercise1);
            instructor1.assignExercise(student1, exercise2);

            instructor2.assignExercise(student2, exercise3);
            instructor2.assignExercise(student2, exercise4);

            instructor3.assignExercise(student3, exercise1);
            instructor3.assignExercise(student3, exercise4);

            // Create a list of students. Add all of the student instances to it.
            List <Student> students = new List <Student>();

            students.Add(student1);
            students.Add(student2);
            students.Add(student3);
            students.Add(student4);


            // Create a list of exercises. Add all of the exercise instances to it.
            List <Exercise> exercises = new List <Exercise>();

            exercises.Add(exercise1);
            exercises.Add(exercise2);
            exercises.Add(exercise3);
            exercises.Add(exercise4);

            // Generate a report that displays which students are working on which exercises.

            foreach (Student student in students)
            {
                foreach (Exercise exercise in student.currentExercises)
                {
                    Console.WriteLine($"{student.firstName} is working on {exercise.name}");
                }
            }
        }