'How to generate user specific instances of an exam object with unique questions
I'm creating an online examination system where I have an exam with a list of questions and need to generate a unique instance/record for each user taking the exam. The questions in each instance are not the same but can contain variations (different answers, different blank spaces to fill in. etc.)
The exam will be created for eg. 10 users and I need to create 10 unique variations of the exam. I am struggling with how to best model this exam instance in my application.
I am using a .NET Core API with Entity Framework and a PostgreSQL DB. This is what my Exam model looks like right now
// This is what the teacher creates - a template
public class Exam
{
[Key]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Status { get; set; }
[Required]
public DateTime StartDate { get; set; }
[Required]
public DateTime EndDate { get; set; }
[Required]
public Semester Semester { get; set; }
[Required]
public ICollection<Question> Questions { get; set; }
public ICollection<Tag> Tags { get; set; }
public Exam(){
this.Tags = new List<Tag>();
this.Questions = new List<Question>();
}
}
And I thought of creating something like this for the Exam Instance
// This is what the student receives to complete - a specific instance
public class ExamInstance
{
[Key]
public int Id { get; set; }
[Required]
public Exam Exam { get; set; }
[Required]
public ICollection<QuestionInstance> QuestionInstances { get; set; }
[Required]
public User User { get; set; }
public ExamInstance(Exam exam, User user)
{
this.Exam = exam;
this.User = user;
this.QuestionInstances = new List<QuestionInstance>();
GenerateQuestionInstances();
}
private void GenerateQuestionInstances()
{
// Here generate the unique questions to be included in test instance from list of questions in this.Exam
}
}
And then just creating an Exam Instance for each user when an exam is created
// Method in controller, service etc.
foreach (User user in exam.Semester.EnrolledStudents)
{
ExamInstance examInstance = new ExamInstance(exam, user);
_repository.CreateExamInstance(examInstance);
}
I can't help but feel this is not the best way to go about it. Is there any standard way to create records of an "instance" class from a "template" class (don't know how better to describe it). I tried looking at the use of design patterns but it doesn't seem to me like anything fits here.
Any help is appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
