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.
93 lines
3.2 KiB
93 lines
3.2 KiB
using DataManagers;
|
|
using DbConnectionLibrairie;
|
|
using DTOs;
|
|
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 ServiceManagers
|
|
{
|
|
public class QuestionServiceManager(IQuestionManager<Question> manager) : IQuestionManager<QuestionDto>
|
|
{
|
|
|
|
private IQuestionManager<Question> manager = manager;
|
|
|
|
public async Task<QuestionDto> addQuestion(QuestionDto question)
|
|
{
|
|
return await Task.FromResult<QuestionDto>((await manager.addQuestion(question.ToModel())).ToDto());
|
|
}
|
|
|
|
public async Task<IEnumerable<QuestionDto>> addQuestions(IEnumerable<QuestionDto> questions)
|
|
{
|
|
var tmp = new List<Question>();
|
|
foreach (var question in questions)
|
|
{
|
|
tmp.Add(question.ToModel());
|
|
}
|
|
var res = await manager.addQuestions(tmp);
|
|
var tmp2 = new List<QuestionDto>();
|
|
foreach (var item in res)
|
|
{
|
|
tmp2.Add(item.ToDto());
|
|
}
|
|
return tmp2;
|
|
}
|
|
|
|
public int getNbQuestions()
|
|
{
|
|
return manager.getNbQuestions();
|
|
}
|
|
|
|
public async Task<QuestionDto?> getQuestion(int id)
|
|
{
|
|
return await Task.FromResult<QuestionDto?>((await manager.getQuestion(id))?.ToDto());
|
|
}
|
|
|
|
public async Task<QuestionDto?> getQuestion(string content)
|
|
{
|
|
return (await manager.getQuestion(content))?.ToDto();
|
|
}
|
|
|
|
public async Task<(int nbPages, IEnumerable<QuestionDto>? questions)> getQuestions(int nb, int count, QuestionOrderCriteria orderCriteria = QuestionOrderCriteria.ById)
|
|
{
|
|
var res = await manager.getQuestions(nb, count, orderCriteria);
|
|
return (res.nbPages, res.questions?.Select(q => q.ToDto()));
|
|
}
|
|
|
|
public async Task<(int nbPages, IEnumerable<QuestionDto>? questions)?> getQuestionsByChapterAndDifficulty(int idChapter, int difficulty, int nb, int count, QuestionOrderCriteria orderCriteria = QuestionOrderCriteria.ById)
|
|
{
|
|
var res = await manager.getQuestionsByChapterAndDifficulty(idChapter, difficulty, nb, count, orderCriteria);
|
|
if (res == null) return null;
|
|
return (res?.nbPages ?? getNbQuestions() / count, res?.questions?.Select(q => q.ToDto()));
|
|
}
|
|
|
|
public async Task<QuestionDto?> removeQuestion(QuestionDto question)
|
|
{
|
|
return (await manager.removeQuestion(question.ToModel()))?.ToDto();
|
|
}
|
|
|
|
public async Task<QuestionDto?> removeQuestion(int id)
|
|
{
|
|
return (await manager.removeQuestion(id))?.ToDto();
|
|
}
|
|
|
|
public async Task<QuestionDto?> updateQuestion(int id, QuestionDto question)
|
|
{
|
|
return (await manager.updateQuestion(id, question.ToModel()))?.ToDto();
|
|
}
|
|
|
|
public async Task<QuestionDto?> updateQuestionNbFalls(int id)
|
|
{
|
|
return (await manager.updateQuestionNbFalls(id))?.ToDto();
|
|
}
|
|
}
|
|
}
|