Exemplo n.º 1
0
        public IHttpActionResult PostEnrollStudent(int classRoomId, ClassRoomEnrollStudentDto enroll)
        {
            var userData = IdentityHelper.GetLoggedInUser(RequestContext);

            logger.Info("Enroll Student {@studentId} in ClassRoom {@classRoomId} {@enrollData} by {@userData}", enroll.StudentId, enroll.ClassRoomId, enroll, userData);

            if (classRoomId != enroll.ClassRoomId)
            {
                return(BadRequest("Class identities do not match."));
            }

            return(Ok(service.EnrollStudent(enroll)));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Enroll student in classroom
        /// OPTIONS: enroll in classroom, enroll in program
        /// TODO use converter for classroom
        /// </summary>
        /// <param name="enroll"></param>
        /// <returns></returns>
        public ClassRoomDto EnrollStudent(ClassRoomEnrollStudentDto enroll)
        {
            // Check if classroom is ok
            ClassRoom classRoom = db.ClassRoomsRepository.GetByID(enroll.ClassRoomId);

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

            StudentUser student = db.StudentsRepository.Get(s => s.Id == enroll.StudentId).FirstOrDefault();

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

            // --- IF STUDENT IS ENROLLED:

            if (student.ClassRoomId != null)
            {
                // check if already registered for a course
                var takingCourse = db.TakingsRepository.Get(t => t.Student.Id == student.Id).FirstOrDefault();

                if (takingCourse != null)
                {
                    // can't switch classroom, too late
                    logger.Info("Student {@studentId} from classroom {@classRoomId} is enrolled in a course, cannot change classRooms anymore", student.Id, classRoom.Id);
                    var ex = new StudentEnrolledInCourseException(string.Format("Student {0} from classroom {1} is enrolled in a course, cannot change classRooms anymore", student.Id, classRoom.Id));
                    ex.Data.Add("studentId", student.Id);
                    ex.Data.Add("classRoomId", classRoom.Id);
                    throw ex;
                }
            }

            // Two strategies with current model:
            // -- 1. Change ClassRoom property of student.
            // -- 2. Update Students collection of classroom.
            // -- (3.) with associative table

            // with the collection stuff we have one problem:
            // well, let's find out, dear...

            var enrolled = classRoom.Students;

            // Can we check like this:
            if (enrolled.Where(e => e.Id == student.Id).FirstOrDefault() != null)
            {
                // student is already enrolled, quit
                return(null);
            }

            enrolled.Add(student);

            db.Save();

            // This is only the classroom with the list of enrolled students
            // no courses.
            return(db.ClassRoomsRepository.Get(c => c.Id == classRoom.Id)
                   .Select(cr => new ClassRoomDto()
            {
                ClassRoomId = cr.Id,
                Name = cr.Name,
                Program = null,
                SchoolGrade = cr.ClassGrade,
                Students = cr.Students.Select(s => new ClassRoomDto.ClassRoomStudentDto()
                {
                    FullName = s.FirstName + " " + s.LastName,
                    StudentId = s.Id
                }).ToList()
            })
                   .FirstOrDefault());
        }
Exemplo n.º 3
0
 public ClassRoomDto EnrollStudent(ClassRoomEnrollStudentDto enroll)
 {
     throw new NotImplementedException();
 }