Exemple #1
0
        public async Task <TeacherStudentResource> AddCourse([FromBody] AddCourseStudent st_course)
        {
            int lowest = 0;
            int tlow;
            //here otherId is CourseId

            var teachers = await IStudent.getTeachers(st_course.otherId);   //using courseId

            int[] teachercount = new int[teachers.Count];
            //to find teacher with lowest students
            foreach (var t in teachers)
            {
                tlow = teachers.IndexOf(t);
                //teachercount[tlow] = db.TeacherStudent.Where(ts => ts.TeacherId == t.TeacherId).Count();

                teachercount[tlow] = IStudent.getTeacherStudentCount(t.TeacherId, false);

                if (teachercount[lowest] > teachercount[tlow] && lowest != tlow)
                {
                    lowest = tlow;
                }
            }

            //teachers[lowest].TeacherId; is teacherId. lowest is index of the teacherId to select
            var res = new TeacherStudent();

            res.StudentId = st_course.studentId;
            res.TeacherId = teachers[lowest].TeacherId;
            IStudent.AdderAsync(res);
            TeacherNotification(teachers[lowest].TeacherId, st_course.studentId, "S", 0);

            return(mapper.Map <TeacherStudent, TeacherStudentResource>(res));
        }
        public Teacher AddStudent(Guid teacherId, Student student)
        {
            Teacher teacher = _teacherRepository.FindById(teacherId);

            TeacherStudent teacherStudent = new TeacherStudent
            {
                TeacherId = teacher.UserId,
                Teacher   = teacher,
                StudentId = student.UserId,
                Student   = student,
                Status    = "active"
            };

            teacher.TeacherStudents.Add(teacherStudent);
            _teacherRepository.Update(teacher);

            return(teacher);
        }
        public Teacher RemoveStudent(Guid teacherId, Student student)
        {
            Teacher teacher = _teacherRepository.FindTeacherWithStudentsAndCoursesById(teacherId);

            TeacherStudent studentToRemove = teacher.TeacherStudents.FirstOrDefault(tchstd => tchstd.StudentId == student.UserId);

            teacher.TeacherStudents.Remove(studentToRemove);

            foreach (var course in teacher.Courses)
            {
                StudentCourse studentCourse = student.StudentCourses.FirstOrDefault(stdcou => stdcou.CourseId == course.Id);

                student.StudentCourses.Remove(studentCourse);
            }

            _studentService.UpdateStudent(student);
            _teacherRepository.Update(teacher);

            return(teacher);
        }
        public async Task <IActionResult> Create([Bind("ID,Name,Surname,Phone")] Students students)
        {
            if (ModelState.IsValid)
            {
                var a = _context.Add(students);
                await _context.SaveChangesAsync();

                TeacherStudent teacherStudent = new TeacherStudent
                {
                    StudentID = a.Entity.ID,
                    TeacherID = User.FindFirstValue(ClaimTypes.NameIdentifier)
                };
                await _context.TeacherStudent.AddAsync(teacherStudent);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(students));
        }
Exemple #5
0
 public int Remover(TeacherStudent ob)
 {
     db.Remove(ob); return(1);
 }
Exemple #6
0
 public int AdderAsync(TeacherStudent ob)
 {
     db.AddAsync(ob); return(1);
 }