internal Message DeleteCourseOnId(int courseId) { Message msg = new Message(); try { var course = query.GetCourseById(context, courseId); if (course != null) { query.DeleteCourseOnId(context, course); msg.status = true; } else { msg.message = $"There is no Course with id = {courseId}"; msg.status = false; } } catch (Exception e) { msg.message = $"Internal Error : {e}"; msg.status = false; } return(msg); }
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); }