You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.01-QCM_MuscuMaths/WebApi/Model/Question.cs

88 lines
2.7 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
public class Question
{
/// <summary>
/// represent a mathematical question
/// attributes :
/// id : identifier of the question in the database
/// content : the content of the question
/// difficulty : difficulty (between 1 and 3 included) of the question
/// nbFails : number of time that people fail on this question
/// idChapter : identifier of the chapter of the question
/// idAnswerGood : identifier of the right answer to this question
/// chapter : the chapter of the question
/// answerGood : the right answer to this question
/// </summary>
private int id;
private string? content;
private int difficulty;
private int nbFalls;
private int idChapter;
private int idAnswerGood;
private Chapter? chapter;
private Answer? answerGood;
public int? Id
{
get => id == -1 ? null : id;
private set { id = value == null || value < -1 ? -1 : value.Value; }
}
public string Content
{
get => content == null ? "" : content;
set { content = value == "" ? null : value;}
}
public int Difficulty
{
get => difficulty;
set { difficulty = value < 0 ? 0 : value; }
}
public int NbFalls
{
get => nbFalls;
set { nbFalls = value < 0 ? 0 : value; }
}
public int? IdChapter
{
get => idChapter == -1 ? null : idChapter;
private set { idChapter = value == null || value < -1 ? -1 : value.Value; }
}
public int? IdAnswerGood
{
get => idAnswerGood == -1 ? null : idAnswerGood;
set { idAnswerGood = value == null || value < -1 ? -1 : value.Value; }
}
public Chapter? Chapter
{
get => chapter;
set { chapter = value; IdChapter = value == null ? -1 : value.Id; }
}
public Answer? AnswerGood
{
get => answerGood;
set { answerGood = value; IdAnswerGood = value == null ? -1 : value.Id; }
}
public Question(string content, Chapter? chapter = null, int id = -1, Answer? answerGood = null)
{
Id = id;
Content = content;
Difficulty = 1;
NbFalls = 0;
Chapter = chapter;
AnswerGood = answerGood;
}
}
}