public IHttpActionResult addTeacherClassroom([FromBody] TeacherClassroom teacherClassroom) { var repo = new ClassroomsRepository(); if (repo.AddClassroomToTeacher(teacherClassroom.TeacherId, teacherClassroom.ClassroomId)) { return(Ok()); } else { return(BadRequest()); } }
public async Task <TeacherClassroom> AddTeacherClassroom(int idTeacher, int idClass) { var teacher = context.User.Find(idTeacher); var classroom = context.Classroom.Find(idClass); if (teacher != null && classroom != null) { var teacherClass = new TeacherClassroom(); teacherClass.IdClassroom = idClass; teacherClass.IdUser = idTeacher; context.TeacherClassroom.Add(teacherClass); await context.SaveChangesAsync(); return(teacherClass); } return(null); }
public async Task <TeacherClassroom> UpdateStudent(int idTeacherClassroom, TeacherClassroom teacherClassroom) { try { var oldTeacherClassroom = context.TeacherClassroom.FirstOrDefault(tc => tc.Id == idTeacherClassroom); if (oldTeacherClassroom != null) { oldTeacherClassroom.IdClassroom = teacherClassroom.IdClassroom; oldTeacherClassroom.IdUser = teacherClassroom.IdUser; await context.SaveChangesAsync(); return(oldTeacherClassroom); } return(null); } catch (Exception ex) { Console.WriteLine("Error: ", ex.Message); return(null); } }