public ServerResponse <ClassroomDTO> GetByTeacher(int idTeacher) { var repo = new ClassroomsRepository(); var result = repo.RetrieveByTeacher(idTeacher); return(new ServerResponse <ClassroomDTO>() { Data = result, Result = result != null }); }
public override void InitParams() { dbSet = _context.Classrooms; r = new ClassroomsRepository(_context); model1 = new Classroom { Capacity = 30, ClassroomNumber = 201, Floor = 2 }; model2 = new Classroom { Capacity = 40, ClassroomNumber = 202, Floor = 2 }; }
public ServerResponse <ClassroomDTO> GetAll() { var repo = new ClassroomsRepository(); var result = repo.RetrieveClassrooms(); return(new ServerResponse <ClassroomDTO>() { Data = result, Result = result != null }); }
public IHttpActionResult Delete(ChildClassroom childClassroom) { try { var repository = new ClassroomsRepository(); repository.Eliminar(childClassroom); return(Ok()); } catch { return(BadRequest()); } }
public IHttpActionResult addTeacherClassroom([FromBody] TeacherClassroom teacherClassroom) { var repo = new ClassroomsRepository(); if (repo.AddClassroomToTeacher(teacherClassroom.TeacherId, teacherClassroom.ClassroomId)) { return(Ok()); } else { return(BadRequest()); } }
static Unit() { _context = new MyAppDbContext("MyAppConnStr"); AddressesRepository = new AddressesRepository(_context); ClassroomsRepository = new ClassroomsRepository(_context); DepartmentsRepository = new DepartmentsRepository(_context); GroupsRepository = new GroupsRepository(_context); GroupTimetablesRepository = new GroupTimetablesRepository(_context); MarksRepository = new MarksRepository(_context); PairTimetablesRepository = new PairTimetablesRepository(_context); PhonesRepository = new PhonesRepository(_context); SpecialitiesRepository = new SpecialitiesRepository(_context); StudentsRepository = new StudentsRepository(_context); SubjectsRepository = new SubjectsRepository(_context); TeachSubjsRepository = new TeachSubjsRepository(_context); TeachersRepository = new TeachersRepository(_context); TimetablesRepository = new TimetablesRepository(_context); }
private HttpResponseMessage ValidateModel(CreateEditScheduleVM model) { /// Some basic validity checks /// // - Is the beginning time lower than the ending time ? - // if (model.BeginningTime >= model.EndingTime) { HttpError err = new HttpError("The ending time must be greater than the beginning time."); return(Request.CreateResponse(HttpStatusCode.NotAcceptable, err)); } // - At least one student must take part to the lesson - // if (model.Students.Length == 0) { HttpError err = new HttpError("You must select at least one student for that lesson."); return(Request.CreateResponse(HttpStatusCode.NotAcceptable, err)); } // - Are all elements to create the schedule actually available at the given date and times? - // List <string> availability = TestAvailability(model); if (availability.Count > 0) { return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, new HttpError(string.Join(@"\\", availability)))); } // - Is the classroom big enough for all the students? - // Classroom classroom = new ClassroomsRepository().Classroom(model.ClassroomID); int nbStudents = model.Students.Where(s => s != null).Count(); if (classroom.AmountStudentsMax < nbStudents) { return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, new HttpError("The selected classroom is too small for the amount of users.\\" + classroom.AmountStudentsMax.ToString() + " places for " + nbStudents.ToString() + " students."))); } return(Request.CreateResponse(HttpStatusCode.OK)); }
public IHttpActionResult Post([FromBody] Classroom classroom) { if (classroom.Id != null) { return(BadRequest()); } if (classroom.Name == null) { return(BadRequest()); } var repo = new ClassroomsRepository(); try { repo.SaveClassroom(classroom); } catch (Exception ex) { Console.WriteLine(ex.Message); return(InternalServerError()); } return(Ok()); }
public void Post([FromBody] ChildClassroom childClassroom) { var repo = new ClassroomsRepository(); repo.AddClassroomToChild(childClassroom.ChildId, childClassroom.ClassroomId); }
private List <string> TestAvailability(CreateEditScheduleVM schedule) { // Let's check if all data are available at the given day and times, starting with the teacher Course course = new CoursesRepository().Course(schedule.CourseID); if (course == null) { return(new List <string> { "The selected course is invalid." }); } Schedule availability = repository.TeacherAvailability(course.TeacherID, schedule.WeekDay, schedule.BeginningTime.ToString(ScheduleConstants.TIME_FORMAT), schedule.EndingTime.ToString(ScheduleConstants.TIME_FORMAT)); if (availability != null && availability.ID != schedule.ID) { return(new List <string> { course.Teacher.ToString() + " is not available at the given day and times:", availability.ToString() }); } // Then, we can check if the room is available Classroom classroom = new ClassroomsRepository().Classroom(schedule.ClassroomID); if (classroom == null) { return(new List <string> { "The selected classroom is invalid." }); } availability = repository.ClassroomAvailability(schedule.ClassroomID, schedule.WeekDay, schedule.BeginningTime.ToString(ScheduleConstants.TIME_FORMAT), schedule.EndingTime.ToString(ScheduleConstants.TIME_FORMAT)); if (availability != null && availability.ID != schedule.ID) { return(new List <string> { "The classroom " + classroom.Name + " is not available at the given day and times:", availability.ToString() }); } // Finally, let's check if all the students are available for the lesson foreach (string studentId in schedule.Students) { availability = repository.StudentAvailability(studentId, schedule.WeekDay, schedule.BeginningTime.ToString(ScheduleConstants.TIME_FORMAT), schedule.EndingTime.ToString(ScheduleConstants.TIME_FORMAT)); if (availability != null && availability.ID != schedule.ID) { return(new List <string> { new UsersRepository().UserById(studentId).ToString() + " is not available at the given day and times:", availability.ToString() }); } } return(new List <string>()); }
public ClassroomsController(ClassroomsRepository classroomsRepository) { this.classroomsRepository = classroomsRepository; }
public ClassroomsController() { this.classroomsRepository = new ClassroomsRepository(new Academy()); }