+// Recieve New Lecture Form
+app.post( '/course/:id', checkAjax, loadUser, loadCourse, function( req, res ) {
+ var course = req.course;
+ // Create new lecture from Lecture schema
+ var lecture = new Lecture;
+
+ if( ( ! course ) || ( ! course.authorized ) ) {
+ return sendJson(res, {status: 'error', message: 'There was a problem trying to create a lecture'})
+ }
+
+ // Populate lecture with form data
+ lecture.name = req.body.name;
+ lecture.date = req.body.date;
+ lecture.course = course._id;
+ lecture.creator = req.user._id;
+
+ // Save lecture to database
+ lecture.save( function( err ) {
+ if( err ) {
+ // XXX better validation
+ sendJson(res, {status: 'error', message: 'Invalid parameters!'} );
+ } else {
+ sendJson(res, {status: 'ok', message: 'Created new lecture'} );
+ }
+ });
+});
+