Example #1
0
 public static SemesterTermDto From(Model.SemesterTerm term)
 {
     return(new SemesterTermDto
     {
         Id = term.Id,
         Name = term.Name
     });
 }
 public void ValidateSemester(Model.SemesterTerm semester, String errorString)
 {
     if (semester == null)
     {
         throw new HttpResponseException(Request.CreateErrorResponse(
                                             HttpStatusCode.NotFound, errorString));
     }
 }
Example #3
0
 public static SemesterTermDto From(Model.SemesterTerm s)
 {
     return(new SemesterTermDto()
     {
         Id = s.Id,
         Name = s.Name
     });
 }
Example #4
0
 private IEnumerable <CourseSectionDto> GetCourseSection(Model.SemesterTerm term)
 {
     if (term == null)
     {
         throw new HttpResponseException(Request.CreateErrorResponse(
                                             HttpStatusCode.NotFound, $"Invalid semester found"));
     }
     return(term.CourseSections.Select(CourseSectionDto.From));
 }
Example #5
0
        public Model.RegistrationResults RegisterForCourse([FromBody] RegistrationDto studentCourse)
        {
            Model.Student student = mContext.Students.Where(s => s.Id == studentCourse.StudentID).FirstOrDefault();
            // Simulate a slow connection / complicated operation by sleeping.
            Thread.Sleep(3000);

            if (student == null)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                                            $"Student id \"{studentCourse.StudentID}\" not found"));
            }

            Model.SemesterTerm term = mContext.SemesterTerms.Where(
                t => t.Id == studentCourse.CourseSection.SemesterTermId)
                                      .SingleOrDefault();

            if (term == null)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                                            $"Semester id \"{studentCourse.CourseSection.SemesterTermId}\" not found"));
            }

            Model.CourseSection section = term.CourseSections.SingleOrDefault(
                c => c.CatalogCourse.DepartmentName == studentCourse.CourseSection.CatalogCourse.DepartmentName &&
                c.CatalogCourse.CourseNumber == studentCourse.CourseSection.CatalogCourse.CourseNumber &&
                c.SectionNumber == studentCourse.CourseSection.SectionNumber);
            if (section == null)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                                            $"Course named \"{studentCourse.CourseSection.CatalogCourse.DepartmentName}" +
                                                                            $"{studentCourse.CourseSection.CatalogCourse.CourseNumber}\"-" +
                                                                            $"{studentCourse.CourseSection.SectionNumber} not found"));
            }

            var regResult = student.CanRegisterForCourseSection(section);

            if (regResult == Model.RegistrationResults.Success)
            {
                section.EnrolledStudents.Add(student);
                mContext.SaveChanges();
            }

            return(regResult);
        }