Ejemplo n.º 1
0
        public IActionResult AddStudentToCourseSave(int cId, int sId)
        {
            var course = CourseRepo.FindCourse(cId);

            if (course == null)
            {
                return(NotFound());
            }

            var student = StudentRepo.FindStudent(sId);

            if (student == null)
            {
                return(NotFound());
            }

            foreach (var item in course.StudentsCourses)//is there student
            {
                if (item.StudentId == sId)
                {
                    return(RedirectToAction(nameof(Details), new { id = cId }));
                }
            }

            CourseRepo.AddStudentToCourse(course, student);//relationship student + course

            return(RedirectToAction(nameof(Details), new { id = cId }));
        }
Ejemplo n.º 2
0
        public void ExecuteInsert(string[] commandWords)
        {
            string[] cW = commandWords;

            if (cW[5] == "course")
            {
                string courseName = cW[6];
                string courseId   = cW[7];

                ICourse courseToInsertInto = null;

                foreach (var currentCourse in Course.CourseList)
                {
                    if (currentCourse.CourseName.ToLower() == courseName.ToLower() && currentCourse.Id == ulong.Parse(courseId))
                    {
                        courseToInsertInto = currentCourse;
                    }
                }

                switch (cW[1])
                {
                case "student":
                    string            studentName = cW[2];
                    string            studentId   = cW[3];
                    CourseParticipant studentToInsert;

                    foreach (var currentStudent in Person.GetAllClients())
                    {
                        if (currentStudent.FirstName.ToLower() == studentName.ToLower() &&
                            currentStudent.Id == ulong.Parse(studentId))
                        {
                            studentToInsert = (CourseParticipant)currentStudent;
                            courseToInsertInto.AddStudentToCourse(studentToInsert);
                        }
                    }
                    break;

                case "teacher":
                    string  teacherName = cW[2];
                    string  teacherId   = cW[3];
                    Teacher teacherToInsert;

                    foreach (var currentTeacher in Person.GetAllTeachers())
                    {
                        if (currentTeacher.FirstName.ToLower() == teacherName.ToLower() &&
                            currentTeacher.Id == ulong.Parse(teacherId))
                        {
                            teacherToInsert = (Teacher)currentTeacher;
                            courseToInsertInto.AddTeachersToCourse(teacherToInsert);
                        }
                    }
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public bool JoinCourse(ICourse course)
        {
            if (Validation.CheckIfObjectIsNull(course))
            {
                throw new ArgumentNullException();
            }

            course.AddStudentToCourse(this);

            return(true);
        }