Example #1
0
        public void removeCourse()
        {
            int idToBeDeleted = idInput("of the student to be deleted");


            using (StudentiEntities studentiEntities = new StudentiEntities())
            {
                Predmeti courseToBeDeleted = studentiEntities.Predmeti.FirstOrDefault(c => c.Id == idToBeDeleted);

                if (courseToBeDeleted != null)
                {
                    IEnumerable <Studenti> studentis =
                        from Studenti in studentiEntities.Studenti
                        select Studenti;

                    foreach (Studenti student in studentis)
                    {
                        if (student.Predmeti.Contains(courseToBeDeleted))
                        {
                            student.Predmeti.Remove(courseToBeDeleted);
                        }
                    }
                    studentiEntities.Predmeti.Remove(courseToBeDeleted);
                    studentiEntities.SaveChanges();
                }
                else
                {
                    Console.WriteLine("Course with given ID does not exist!");
                }
            }
        }
Example #2
0
        public void updateStudentCourses()
        {
            int    studentId, subjectId;
            string addOrRemoveCourses;

            studentId = idInput("of the student to be updated");


            while (true)
            {
                Console.WriteLine("Enter 1 to remove courses, enter 2 to add courses");
                addOrRemoveCourses = Console.ReadLine().Trim();

                if (addOrRemoveCourses == "1" || addOrRemoveCourses == "2")
                {
                    break;
                }
            }
            subjectId = idInput("of the subject");


            using (StudentiEntities studentiEntities = new StudentiEntities())
            {
                bool idExists = false;

                Studenti studentToBeUpdated        = studentiEntities.Studenti.FirstOrDefault(s => s.Id == studentId);
                Predmeti subjectToBeAddedOrRemoved = studentiEntities.Predmeti.FirstOrDefault(p => p.Id == subjectId);

                if (studentToBeUpdated != null && subjectToBeAddedOrRemoved != null)
                {
                    idExists = true;
                }

                if (addOrRemoveCourses == "1" && idExists)
                {
                    studentToBeUpdated.Predmeti.Remove(subjectToBeAddedOrRemoved);
                    subjectToBeAddedOrRemoved.Studenti.Remove(studentToBeUpdated);
                    studentiEntities.SaveChanges();
                }
                else if (addOrRemoveCourses == "2" && idExists)
                {
                    studentToBeUpdated.Predmeti.Add(subjectToBeAddedOrRemoved);
                    subjectToBeAddedOrRemoved.Studenti.Add(studentToBeUpdated);
                    studentiEntities.SaveChanges();
                }

                if (!idExists)
                {
                    Console.WriteLine("Invalid IDs!");
                }
            }
        }
Example #3
0
        public void addNewCourse()
        {
            Predmeti newCourse = new Predmeti();

            Console.WriteLine("Please insert the new subject name");
            newCourse.Naziv = Console.ReadLine().Trim();

            using (StudentiEntities studentiEntities = new StudentiEntities())
            {
                studentiEntities.Predmeti.Add(newCourse);
                studentiEntities.SaveChanges();
            }
        }
Example #4
0
        public void updateCourse()
        {
            int    idToBeUpdated = idInput("of the course to be updated");
            string nameUpdated;


            Console.WriteLine("Please insert the new course name");
            nameUpdated = Console.ReadLine().Trim();

            using (StudentiEntities studentiEntities = new StudentiEntities())
            {
                Predmeti courseToBeUpdated = studentiEntities.Predmeti.FirstOrDefault(c => c.Id == idToBeUpdated);

                if (courseToBeUpdated != default)
                {
                    courseToBeUpdated.Naziv = nameUpdated;
                    studentiEntities.SaveChanges();
                }
                else
                {
                    Console.WriteLine("Course with given Id does not exist!");
                }
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            Predmeti    newPredmet  = new Predmeti();
            HelperClass helperClass = new HelperClass();

            while (true)
            {
                string input;

                Console.WriteLine("Select one of the options");
                Console.WriteLine("1 - add a new student");
                Console.WriteLine("2 - delete a student");
                Console.WriteLine("3 - update a student personal information");
                Console.WriteLine("4 - update the courses a student in enrolled to");
                Console.WriteLine("5 - add a new course");
                Console.WriteLine("6 - delete a course");
                Console.WriteLine("7 - update a course");
                Console.WriteLine("8 - show all students and classes they are enrolled to");
                Console.WriteLine("9 - show all courses where a student is enrolled");
                Console.WriteLine("10 - exit");

                input = Console.ReadLine().Trim();

                switch (input)
                {
                case "1":
                    helperClass.AddNewStudent();
                    break;

                case "2":
                    helperClass.DeleteStudent();
                    break;

                case "3":
                    helperClass.updateStudentInfo();
                    break;

                case "4":
                    helperClass.updateStudentCourses();
                    break;

                case "5":
                    helperClass.addNewCourse();
                    break;

                case "6":
                    helperClass.removeCourse();
                    break;

                case "7":
                    helperClass.updateCourse();
                    break;

                case "8":
                    helperClass.showAllStudentsEnrolled();
                    break;

                case "9":
                    helperClass.showAllCoursesEndrolled();
                    break;

                default:
                    Environment.Exit(0);
                    break;
                }
            }
        }