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/Answer.cs

52 lines
1.6 KiB

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Model
{
public class Answer
{
/// <summary>
/// define an answer for a Question with Mutiple Choice
/// attributes :
/// id : identifier in the database
/// content : content of the answer
/// idQuestion : the id of the question which it answer to
/// </summary>
private int id;
private string? content;
private int idQuestion;
/// <summary>
/// getters and setters for attributes
/// </summary>
public int? Id
{
get => id == -1 ? null : id; // null = no id
private set { id = value < -1 || value == null ? -1 : value.Value; }
}
public string Content
{
get => content == null ? "" : content;
set { content = value == "" ? null : value; }
}
public int? IdQuestion
{
get => idQuestion == -1 ? null : idQuestion; // null = no idQuestion
private set { idQuestion = value < -1 || value == null ? -1 : value.Value; }
}
/// <summary>
/// constructor of an answer
/// </summary>
/// <param name="content">the content of the answer</param>
/// <param name="id">the id in the database</param>
/// <param name="idQuestion">the id of the question which it answer to</param>
public Answer(string content, int? idQuestion = null, int? id = null)
{
Content = content;
Id = id;
IdQuestion = idQuestion;
}
}
}