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.
47 lines
1.8 KiB
47 lines
1.8 KiB
using DTOs;
|
|
using Entities;
|
|
using Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ExtensionsClassLibrairie
|
|
{
|
|
/// <summary>
|
|
/// define some methods to manipulate entity, model and dto questions :
|
|
/// convert model to DTO, model to Entity, ...
|
|
/// and equality protocols
|
|
/// </summary>
|
|
public static class QuestionExtensionMethods
|
|
{
|
|
// conversion methods
|
|
public static Question ToModel(this QuestionEntity q)
|
|
{
|
|
var tmp = new Question(q.Content, q.Chapter?.ToModel(), q.Id, q.AnswerGood?.ToModel());
|
|
tmp.Difficulty = q.Difficulty;
|
|
tmp.NbFalls = q.NbFalls;
|
|
return tmp;
|
|
}
|
|
public static Question ToModel(this QuestionDto q)
|
|
{
|
|
var tmp = new Question(q.Content, q.Chapter?.ToModel(), q.Id, q.AnswerGood?.ToModel());
|
|
tmp.Difficulty = q.Difficulty;
|
|
tmp.NbFalls = q.NbFalls;
|
|
return tmp;
|
|
}
|
|
public static QuestionDto ToDto(this Question q)
|
|
=> new QuestionDto { Id = q.Id, Content = q.Content, AnswerGood = q.AnswerGood?.ToDto(),
|
|
Chapter = q.Chapter?.ToDto(), Difficulty = q.Difficulty, NbFalls = q.NbFalls };
|
|
public static QuestionEntity ToEntity(this Question q)
|
|
=> new QuestionEntity { Id = q.Id, Content = q.Content, AnswerGood = q.AnswerGood?.ToEntity(),
|
|
Chapter = q.Chapter?.ToEntity(), Difficulty = q.Difficulty, NbFalls = q.NbFalls };
|
|
|
|
// reuse other methods
|
|
public static QuestionDto ToDto(this QuestionEntity q)
|
|
=> q.ToModel().ToDto();
|
|
public static QuestionEntity ToEntity(this QuestionDto q)
|
|
=> q.ToModel().ToEntity();
|
|
}
|
|
} |