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.
109 lines
3.7 KiB
109 lines
3.7 KiB
using DbConnectionLibrairie;
|
|
using Entities;
|
|
using EntityManagers;
|
|
using ExtensionsClassLibrairie;
|
|
using ManagerInterfaces;
|
|
using Model;
|
|
using OrderCriterias;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DataManagers
|
|
{
|
|
public class QuestionDataManager : IQuestionManager<Question>
|
|
{
|
|
|
|
private IQuestionManager<QuestionEntity> manager;
|
|
|
|
public QuestionDataManager(IQuestionManager<QuestionEntity> manager)
|
|
{
|
|
this.manager = manager;
|
|
}
|
|
|
|
public async Task<Question> addQuestion(Question question)
|
|
{
|
|
return await Task.FromResult<Question>((await manager.addQuestion(question.ToEntity())).ToModel());
|
|
}
|
|
|
|
public async Task<IEnumerable<Question>> addQuestions(IEnumerable<Question> questions)
|
|
{
|
|
var tmp = new List<QuestionEntity>();
|
|
foreach (var question in questions)
|
|
{
|
|
tmp.Add(question.ToEntity());
|
|
}
|
|
var res = await manager.addQuestions(tmp);
|
|
var tmp2 = new List<Question>();
|
|
foreach (var item in res)
|
|
{
|
|
tmp2.Add(item.ToModel());
|
|
}
|
|
return tmp2;
|
|
}
|
|
|
|
public int getNbQuestions()
|
|
{
|
|
return manager.getNbQuestions();
|
|
}
|
|
|
|
public async Task<Question?> getQuestion(int id)
|
|
{
|
|
return await Task.FromResult<Question?>((await manager.getQuestion(id))?.ToModel());
|
|
}
|
|
|
|
public async Task<(int nbPages, IEnumerable<Question>? questions)> getQuestions(int nb, int count, QuestionOrderCriteria orderCriteria = QuestionOrderCriteria.ById)
|
|
{
|
|
List<Question>? tmp = new List<Question>();
|
|
var res = await manager.getQuestions(nb, count, orderCriteria);
|
|
if (res.questions == null) tmp = null;
|
|
else
|
|
{
|
|
foreach (var item in res.questions)
|
|
{
|
|
tmp.Add(item.ToModel());
|
|
}
|
|
}
|
|
return await Task.FromResult<(int nbPages, IEnumerable<Question>? questions)>((res.nbPages, tmp));
|
|
}
|
|
|
|
public async Task<(int nbPages, IEnumerable<Question>? questions)?> getQuestionsByChapterAndDifficulty(int idChapter, int difficulty, int nb, int count, QuestionOrderCriteria orderCriteria = QuestionOrderCriteria.ById)
|
|
{
|
|
List<Question>? tmp = new List<Question>();
|
|
var res = await manager.getQuestionsByChapterAndDifficulty(idChapter, difficulty, nb, count, orderCriteria);
|
|
if (res == null) return await Task.FromResult<(int nbPages, IEnumerable<Question>? questions)?>(null);
|
|
if (res.Value.questions == null) tmp = null;
|
|
else
|
|
{
|
|
foreach (var item in res.Value.questions)
|
|
{
|
|
tmp.Add(item.ToModel());
|
|
}
|
|
}
|
|
return await Task.FromResult<(int nbPages, IEnumerable<Question>? questions)>((res.Value.nbPages, tmp));
|
|
}
|
|
|
|
public async Task<Question?> removeQuestion(Question question)
|
|
{
|
|
return (await manager.removeQuestion(question.ToEntity()))?.ToModel();
|
|
}
|
|
|
|
public async Task<Question?> removeQuestion(int id)
|
|
{
|
|
return (await manager.removeQuestion(id))?.ToModel();
|
|
}
|
|
|
|
public async Task<Question?> updateQuestion(int id, Question question)
|
|
{
|
|
return (await manager.updateQuestion(id, question.ToEntity()))?.ToModel();
|
|
}
|
|
|
|
public async Task<Question?> updateQuestionNbFalls(int id)
|
|
{
|
|
return (await manager.updateQuestionNbFalls(id))?.ToModel();
|
|
}
|
|
}
|
|
}
|