如何生成具有独特问题的考试对象的用户特定实例

发布于 2025-01-18 09:58:06 字数 2097 浏览 0 评论 0原文

我正在创建一个在线考试系统,其中我有一个问题列表的考试,并且需要为参加考试的每个用户生成独特的实例/记录。每个实例中的问题都不相同,但可以包含变化(不同的答案,要填充的空白空间不同。等)

将为例如创建考试。我和10个用户需要创建考试的10个独特变体。我正在为如何在应用程序中最好地对此实例进行最佳建模。

我正在使用带有实体框架的.NET Core API和PostgreSQL DB。这就是我的考试模型现在的样子

// 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>();
    }

    
}

,我想为考试实例创建类似的内容

// 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
    }

}

,然后在创建考试时为每个用户创建一个检查实例,

// Method in controller, service etc.

foreach (User user in exam.Semester.EnrolledStudents)
{
   ExamInstance examInstance = new ExamInstance(exam, user);
   _repository.CreateExamInstance(examInstance);
}

我不禁觉得这不是最好的方法去做。是否有任何标准方法可以从“模板”类创建“实例”类的记录(不知道如何更好地描述它)。我尝试查看设计模式的使用,但在我看来,这里似乎并不适合这里。

任何帮助都将受到赞赏。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文