Today’s story was to add support for adding a student to a course’s enrollment. This might seem pretty straightforward, except that we also need to add that user to the Unassigned study group.
What I wanted to do was to have the Course table entries also store the ID of its corresponding Unassigned study group, because otherwise I’d have to do a search query on the Study Group table with the appropriate course ID, and also search for the one that was named “Unassigned.” In addition, I would need to restrict users from naming another study group to Unassigned, since it would mess up this query.
A simpler solution would be to record the ID of the study group and put this in the course table when the course is created, since an Unassigned study group is also created at the same time. It took quite a long time to complete… I had to revisit my DB structure and how I was creating courses first, and also correct the previously added test courses so that they were assigned something appropriate.
The hardest part was probably modifying the course adding operation, since I needed to retrieve both the courseID and studyGroupID, both of which are auto-increment, and so have to be discovered after creation.
And all that was just to set things up for adding users to courses. The rest of the way was relatively complex as well. One of the hardest parts was coming up with a query that would give me all the users who were eligible to be added to a course. For example, you shouldn’t be able to add a user to a course twice. So, I basically had to get a list of all the students who were not enrolled in a class.
This is another example of where a lack of SQL experience hurts me — I’m pretty sure there is a query that I could write that would do this, but I ended up, after some frustration, retrieving all the users, then retrieving all the enrolled users, and finally comparing the lists to get the list of unenrolled users. It’s a performance no-no and bad practice, but under my time constraints, it’s good enough and it works!
The final step was hooking the unenrolled list to the ListBox that I had setup, and thankfully that wasn’t too painful. I did implement it such that you could add multiple users at one time, which is helpful for the user.

I spent about 4x the time on this story than previous stories, so I think this iteration is now overbudgeted. I’ll try the next story, but unless that and the following ones are super easy, I’ll probably close this iteration after that story is completed.