public bool PutTeacherTeachSubject(int id, TeacherTeachSubject teacherTeachSubject)
        {
            if (id != teacherTeachSubject.Id)
            {
                return(false);
            }
            if (db.TeacherTeachSubjectToSchoolClassRepository.Get(x => x.TeacherTeachSubjectId == id) != null) // Ne smemo da menjamo "TeacherTeachSubject" ako je vec vezan za "TeacherTeachSubjectToSchoolClass", jer je Subject vezan za SchoolClass i dalje za Student-e i ocene
            {
                return(false);
            }

            TeacherTeachSubject checkTeacherTeachSubject = db.TeacherTeachSubjectRepository.GetByID(id);

            if (checkTeacherTeachSubject == null)
            {
                return(false);
            }
            checkTeacherTeachSubject.Teacher = db.TeacherRepository.GetByID(teacherTeachSubject.TeacherId);
            checkTeacherTeachSubject.Subject = db.SubjectRepository.GetByID(teacherTeachSubject.SubjectId);

            db.TeacherTeachSubjectRepository.Update(checkTeacherTeachSubject);
            db.Save();
            logger.Info("Updated teacher-teach-subject (id:{0})", checkTeacherTeachSubject.Id);

            return(true);
        }
예제 #2
0
        public IHttpActionResult DeleteTeacherTeachSubject(int id)
        {
            TeacherTeachSubject teacherTeachSubject = service.DeleteTeacherTeachSubject(id);

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

            return(Ok(teacherTeachSubject));
        }
예제 #3
0
        public IHttpActionResult GetTeacherTeachSubjectById(int id)
        {
            TeacherTeachSubject teacherTeachSubject = service.GetTeacherTeachSubjectById(id);

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

            return(Ok(teacherTeachSubject));
        }
        public TeacherTeachSubject DeleteTeacherTeachSubject(int id)
        {
            TeacherTeachSubject teacherTeachSubject = db.TeacherTeachSubjectRepository.GetByID(id);

            if (teacherTeachSubject == null)
            {
                return(null);
            }

            db.TeacherTeachSubjectRepository.Delete(id);
            db.Save();
            logger.Info("Deleted teacher-teach-subject (id:{0})", id);

            return(teacherTeachSubject);
        }
예제 #5
0
        public IHttpActionResult PutTeacherTeachSubject(int id, TeacherTeachSubject teacherTeachSubject)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            bool done = service.PutTeacherTeachSubject(id, teacherTeachSubject);

            if (done == false)
            {
                return(BadRequest());
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #6
0
        public IHttpActionResult PostTeacherTeachSubject(TeacherTeachSubject teacherTeachSubject)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            TeacherTeachSubject postedTeacherTeachSubject = service.PostTeacherTeachSubject(teacherTeachSubject);

            if (postedTeacherTeachSubject == null)
            {
                return(BadRequest());
            }

            return(Created("", postedTeacherTeachSubject));
        }
        public TeacherTeachSubjectToSchoolClass PostTeacherTeachSubjectToSchoolClass(TeacherTeachSubjectToSchoolClass teacherTeachSubjectToSchoolClass)
        {
            TeacherTeachSubject teacherTeachSubject = db.TeacherTeachSubjectRepository.GetByID(teacherTeachSubjectToSchoolClass.TeacherTeachSubjectId);
            SchoolClass         schoolClass         = db.SchoolClassRepository.GetByID(teacherTeachSubjectToSchoolClass.SchoolClassId);

            if (teacherTeachSubject == null || schoolClass == null)
            {
                return(null);
            }
            TeacherTeachSubjectToSchoolClass newTeacherTeachSubjectToSchoolClass = new TeacherTeachSubjectToSchoolClass();

            newTeacherTeachSubjectToSchoolClass.TeacherTeachSubject = teacherTeachSubject;
            newTeacherTeachSubjectToSchoolClass.SchoolClass         = schoolClass;

            db.TeacherTeachSubjectToSchoolClassRepository.Insert(newTeacherTeachSubjectToSchoolClass);

            //-----------------Za svaki dodati "teacherTeachSubjectToSchoolClass" napunimo "teacherTeachSubjectToSchoolClassToStudent"-------------------------
            //-----------------Svaki Student koji ide u taj SchoolClass dobije taj Subject koji predaje taj Teacher tom SchoolClass-u
            TeacherTeachSubjectToSchoolClassToStudent           teacherTeachSubjectToSchoolClassToStudent;
            TeacherTeachSubjectToSchoolClassToStudentAtSemester teacherTeachSubjectToSchoolClassToStudentAtSemester;

            foreach (var item in schoolClass.Students)
            {
                teacherTeachSubjectToSchoolClassToStudent = new TeacherTeachSubjectToSchoolClassToStudent();
                teacherTeachSubjectToSchoolClassToStudent.TeacherTeachSubjectToSchoolClassId = teacherTeachSubjectToSchoolClass.Id;
                teacherTeachSubjectToSchoolClassToStudent.StudentId = item.Id;
                db.TeacherTeachSubjectToSchoolClassToStudentRepository.Insert(teacherTeachSubjectToSchoolClassToStudent);

                // Dodajemo "teacherTeachSubjectToSchoolClassToStudentAtSemester" za oba semestra
                teacherTeachSubjectToSchoolClassToStudentAtSemester = new TeacherTeachSubjectToSchoolClassToStudentAtSemester();
                teacherTeachSubjectToSchoolClassToStudentAtSemester.TeacherTeachSubjectToSchoolClassToStudent = teacherTeachSubjectToSchoolClassToStudent;
                teacherTeachSubjectToSchoolClassToStudentAtSemester.Semester = db.SemesterRepository.GetByID(SemesterEnum.FIRST);
                db.TeacherTeachSubjectToSchoolClassToStudentAtSemesterRepository.Insert(teacherTeachSubjectToSchoolClassToStudentAtSemester);

                teacherTeachSubjectToSchoolClassToStudentAtSemester = new TeacherTeachSubjectToSchoolClassToStudentAtSemester();
                teacherTeachSubjectToSchoolClassToStudentAtSemester.TeacherTeachSubjectToSchoolClassToStudent = teacherTeachSubjectToSchoolClassToStudent;
                teacherTeachSubjectToSchoolClassToStudentAtSemester.Semester = db.SemesterRepository.GetByID(SemesterEnum.SECOND);
                db.TeacherTeachSubjectToSchoolClassToStudentAtSemesterRepository.Insert(teacherTeachSubjectToSchoolClassToStudentAtSemester);
            }
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            db.Save();

            return(teacherTeachSubjectToSchoolClass);
        }
        public TeacherTeachSubject PostTeacherTeachSubject(TeacherTeachSubject teacherTeachSubject)
        {
            Teacher teacher = db.TeacherRepository.GetByID(teacherTeachSubject.TeacherId);
            Subject subject = db.SubjectRepository.GetByID(teacherTeachSubject.SubjectId);

            if (teacher == null || subject == null)
            {
                return(null);
            }
            TeacherTeachSubject newTeacherTeachSubject = new TeacherTeachSubject();

            newTeacherTeachSubject.Teacher = teacher;
            newTeacherTeachSubject.Subject = subject;
            db.TeacherTeachSubjectRepository.Insert(newTeacherTeachSubject);
            db.Save();
            logger.Info("Added new teacher-teach-subject");

            return(teacherTeachSubject);
        }
        public TeacherTeachSubject GetTeacherTeachSubjectById(int id)
        {
            TeacherTeachSubject teacherTeachSubject = db.TeacherTeachSubjectRepository.GetByID(id);

            return(teacherTeachSubject);
        }