public SubjectTeacherDTOOut AddTeacherToSubject(int id, SubjectTEacherDTOIn subjectToUpdt) { Subject subject = GetSubjectByID(id); HashSet <Teacher> teachers = new HashSet <Teacher>(); foreach (var ID in subjectToUpdt.TeacherID) { Teacher teacher = teachersService.GetById(ID); teachers.Add(teacher); } subject.Teachers = teachers; db.SubjectsRepository.Update(subject); db.Save(); IEnumerable <TeacherDTOOutReg> teachersUpdate = teachers.Select(x => Utilities.ConverterDTO.SimpleDTOConverter <TeacherDTOOutReg>(x)); SubjectTeacherDTOOut updatedSubject = new SubjectTeacherDTOOut() { Subject = Utilities.ConverterDTO.SimpleDTOConverter <SubjectDTO>(subject), Teachers = teachersUpdate }; return(updatedSubject); }
public IHttpActionResult PutTeacherInSubject(int id, SubjectTEacherDTOIn subject) { if (id != subject.SubjectID) { return(BadRequest()); } SubjectTeacherDTOOut subjectDTO = subjectsService.AddTeacherToSubject(id, subject); return(Ok(subjectDTO)); }