Пример #1
0
        public College AllotCollege(StudentIdCourseId studentcourse)
        {
            Random r           = new Random();
            var    allColleges = query.GetCollegeOfferingCourse(context, studentcourse.CourseId);
            var    college     = allColleges[r.Next(0, allColleges.Count)];

            return(college);
        }
Пример #2
0
        public Message RegisterStudentToCourse(StudentIdCourseId studentIdCourseId)
        {
            Message msg = new Message();

            CourseQuery courseQuery = new CourseQuery();
            StudentCourseCollegeQuery studentCourseCollegeQuery = new StudentCourseCollegeQuery();
            StudentQuery studentQuery = new StudentQuery();


            if (query.IsStudentRegisteredtoCourse(context, studentIdCourseId.StudentId, studentIdCourseId.CourseId))
            {
                msg.status  = false;
                msg.message = "Student is already registered to the course";
            }
            else if (!query.StudentExists(context, studentIdCourseId.StudentId) ||
                     !courseQuery.courseExistsOnId(context, studentIdCourseId.CourseId))
            {
                msg.status  = false;
                msg.message = "The Student/Course is not registered";
            }


            var college = AllotCollege(studentIdCourseId);

            if (college == null)
            {
                msg.status  = false;
                msg.message = "No colleges currently offer this course";
            }

            StudentCourseCollege studentCourseCollege = new StudentCourseCollege()
            {
                CollegeId = college.Id,
                StudentId = studentIdCourseId.StudentId,
                CourseId  = studentIdCourseId.CourseId,
            };

            try
            {
                studentCourseCollegeQuery.RegisterStudentToCourseAndCollege(context, studentCourseCollege);
                var course = courseQuery.GetCourseById(context, studentIdCourseId.CourseId);
                msg.status  = true;
                msg.message = $"Alloted College: {college.Name} (Id : {college.Id})\n for Course : {course.courseName} (id : {course.Id})";
            }
            catch (Exception e)
            {
                msg.status  = false;
                msg.message = $"Internal Error : {e.Message}";
            }

            return(msg);
        }
Пример #3
0
 public ActionResult RegisterStudentToCourse(StudentIdCourseId studentCourse)
 {
     try
     {
         var msg = studentService.RegisterStudentToCourse(studentCourse);
         if (msg.status)
         {
             return(Ok(msg.message));
         }
         return(BadRequest(msg.message));
     }
     catch (Exception e)
     {
         return(StatusCode(500, e.Message));
     }
 }