Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
 public async Task <TeacherStudent> getTeacherStudent(AddCourseStudent courseStudent, bool isTeacher)
 {
     //if(isTeacher==true)
     return(await db.TeacherStudent
            .Where(ts => ts.StudentId == courseStudent.studentId && ts.TeacherId == courseStudent.otherId)   //here otherId is TeacherId
            .FirstOrDefaultAsync());
 }
Ejemplo n.º 3
0
        public async Task <StudentResource> deleteCourse([FromBody] AddCourseStudent courseStudent)
        {
            //here otherId is TeacherId

            var res = await IStudent.getTeacherStudent(courseStudent, true);

            if (res != null)
            {
                IStudent.Remover(res);
            }
            TeacherNotification(courseStudent.otherId, courseStudent.studentId, "S", 1);
            IStudent.Saver();
            return(await getSDetails(courseStudent.studentId));
        }