|
|
|
@ -0,0 +1,293 @@
|
|
|
|
|
using DbConnectionLibrairie;
|
|
|
|
|
using DTOs;
|
|
|
|
|
using ManagerInterfaces;
|
|
|
|
|
using OrderCriterias;
|
|
|
|
|
using ServiceManagers;
|
|
|
|
|
|
|
|
|
|
namespace WebApi
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// just an interface between service managers and controllers
|
|
|
|
|
/// which contains all service managers methods who just calls
|
|
|
|
|
/// methods of service managers (we don't care about awaiting)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Unit : IAdministratorManager<AdministratorDto>, IAnswerManager<AnswerDto>, IChapterManager<ChapterDto>, ILobbyManager<LobbyDto>, IPlayerManager<PlayerDto>, IQuestionManager<QuestionDto>
|
|
|
|
|
{
|
|
|
|
|
public IAdministratorManager<AdministratorDto> AdministratorManager { get; set; }
|
|
|
|
|
public IAnswerManager<AnswerDto> AnswerManager { get; set; }
|
|
|
|
|
public IChapterManager<ChapterDto> ChapterManager { get; private set; }
|
|
|
|
|
public ILobbyManager<LobbyDto> LobbyManager { get; private set; }
|
|
|
|
|
public IPlayerManager<PlayerDto> PlayerManager { get; private set; }
|
|
|
|
|
public IQuestionManager<QuestionDto> QuestionManager { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Unit(MyDbContext dbContext)
|
|
|
|
|
{
|
|
|
|
|
AdministratorManager = new AdministratorServiceManager(dbContext);
|
|
|
|
|
AnswerManager = new AnswerServiceManager(dbContext);
|
|
|
|
|
ChapterManager = new ChapterServiceManager(dbContext);
|
|
|
|
|
LobbyManager = new LobbyServiceManager(dbContext);
|
|
|
|
|
PlayerManager = new PlayerServiceManager(dbContext);
|
|
|
|
|
QuestionManager = new QuestionServiceManager(dbContext);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNbAdmins()
|
|
|
|
|
{
|
|
|
|
|
return AdministratorManager.getNbAdmins();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<AdministratorDto> addAdmin(AdministratorDto admin)
|
|
|
|
|
{
|
|
|
|
|
return AdministratorManager.addAdmin(admin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<AdministratorDto?> removeAdmin(AdministratorDto admin)
|
|
|
|
|
{
|
|
|
|
|
return AdministratorManager.removeAdmin(admin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<AdministratorDto?> removeAdmin(int id)
|
|
|
|
|
{
|
|
|
|
|
return AdministratorManager.removeAdmin(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<(int nbPages, IEnumerable<AdministratorDto>? administrators)> getAdministrators(int page, int count, AdministratorOrderCriteria orderCriteria = AdministratorOrderCriteria.ById)
|
|
|
|
|
{
|
|
|
|
|
return AdministratorManager.getAdministrators(page, count, orderCriteria);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<AdministratorDto?> getAdministrator(int id)
|
|
|
|
|
{
|
|
|
|
|
return AdministratorManager.getAdministrator(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<AdministratorDto?> getAdministratorByUsername(string username)
|
|
|
|
|
{
|
|
|
|
|
return AdministratorManager.getAdministratorByUsername(username);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<bool> setPassword(string username, string newHashedPassword)
|
|
|
|
|
{
|
|
|
|
|
return AdministratorManager.setPassword(username, newHashedPassword);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<AdministratorDto?> updateAdministrator(int id, AdministratorDto admin)
|
|
|
|
|
{
|
|
|
|
|
return AdministratorManager.updateAdministrator(id, admin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNbAnswers()
|
|
|
|
|
{
|
|
|
|
|
return AnswerManager.getNbAnswers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<(int nbPages, IEnumerable<AnswerDto>? answers)> getAnswers(int nb, int count, AnswerOrderCriteria orderCriteria = AnswerOrderCriteria.ById)
|
|
|
|
|
{
|
|
|
|
|
return AnswerManager.getAnswers(nb, count, orderCriteria);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<IEnumerable<AnswerDto>?> getAnswers(string content)
|
|
|
|
|
{
|
|
|
|
|
return AnswerManager.getAnswers(content);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<IEnumerable<AnswerDto>?> getAnswersByIdQuestion(int id)
|
|
|
|
|
{
|
|
|
|
|
return AnswerManager.getAnswersByIdQuestion(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<AnswerDto?> updateAnswer(int id, AnswerDto answer)
|
|
|
|
|
{
|
|
|
|
|
return AnswerManager.updateAnswer(id, answer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<AnswerDto?> removeAnswer(int id)
|
|
|
|
|
{
|
|
|
|
|
return AnswerManager.removeAnswer(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<AnswerDto?> removeAnswer(AnswerDto answer)
|
|
|
|
|
{
|
|
|
|
|
return AnswerManager.removeAnswer(answer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<AnswerDto> addAnswer(AnswerDto answer)
|
|
|
|
|
{
|
|
|
|
|
return AnswerManager.addAnswer(answer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<AnswerDto?> getAnswer(int id)
|
|
|
|
|
{
|
|
|
|
|
return AnswerManager.getAnswer(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNbChapters()
|
|
|
|
|
{
|
|
|
|
|
return ChapterManager.getNbChapters();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<ChapterDto> addChapter(ChapterDto chapter)
|
|
|
|
|
{
|
|
|
|
|
return ChapterManager.addChapter(chapter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<ChapterDto?> removeChapter(ChapterDto chapter)
|
|
|
|
|
{
|
|
|
|
|
return ChapterManager.removeChapter(chapter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<ChapterDto?> removeChapter(int id)
|
|
|
|
|
{
|
|
|
|
|
return ChapterManager.removeChapter(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<ChapterDto?> getChapter(int id)
|
|
|
|
|
{
|
|
|
|
|
return ChapterManager.getChapter(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<ChapterDto?> getChapter(string name)
|
|
|
|
|
{
|
|
|
|
|
return ChapterManager.getChapter(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<(int nbPages, IEnumerable<ChapterDto>? chapters)> getChapters(int nb, int count, ChapterOrderCriteria orderCriteria = ChapterOrderCriteria.ById)
|
|
|
|
|
{
|
|
|
|
|
return ChapterManager.getChapters(nb, count, orderCriteria);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<ChapterDto?> updateChapter(int id, string newName)
|
|
|
|
|
{
|
|
|
|
|
return ChapterManager.updateChapter(id, newName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNbLobbies()
|
|
|
|
|
{
|
|
|
|
|
return LobbyManager.getNbLobbies();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<LobbyDto> addLobby(LobbyDto lobby)
|
|
|
|
|
{
|
|
|
|
|
return LobbyManager.addLobby(lobby);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<LobbyDto?> removeLobby(LobbyDto lobby)
|
|
|
|
|
{
|
|
|
|
|
return LobbyManager.removeLobby(lobby);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<LobbyDto?> removeLobby(int id)
|
|
|
|
|
{
|
|
|
|
|
return LobbyManager.removeLobby(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<(int nbPages, IEnumerable<LobbyDto>? lobbies)> getLobbies(int nb, int count, LobbyOrderCriteria orderCriteria = LobbyOrderCriteria.ById)
|
|
|
|
|
{
|
|
|
|
|
return LobbyManager.getLobbies(nb, count, orderCriteria);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<LobbyDto?> getLobby(int id)
|
|
|
|
|
{
|
|
|
|
|
return LobbyManager.getLobby(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNbPlayers()
|
|
|
|
|
{
|
|
|
|
|
return PlayerManager.getNbPlayers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<PlayerDto> addPlayer(PlayerDto player)
|
|
|
|
|
{
|
|
|
|
|
return PlayerManager.addPlayer(player);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<PlayerDto?> removePlayer(PlayerDto player)
|
|
|
|
|
{
|
|
|
|
|
return PlayerManager.removePlayer(player);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<PlayerDto?> removePlayer(int id)
|
|
|
|
|
{
|
|
|
|
|
return PlayerManager.removePlayer(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<(int nbPages, IEnumerable<PlayerDto>? players)> getPlayers(int nb, int count, PlayerOrderCriteria orderCriteria = PlayerOrderCriteria.ById)
|
|
|
|
|
{
|
|
|
|
|
return PlayerManager.getPlayers(nb, count, orderCriteria);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<PlayerDto?> getPlayer(int id)
|
|
|
|
|
{
|
|
|
|
|
return PlayerManager.getPlayer(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<PlayerDto?> getPlayer(string nickname)
|
|
|
|
|
{
|
|
|
|
|
return PlayerManager.getPlayer(nickname);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<IEnumerable<PlayerDto>?> getPlayersInALobby(int idLobby)
|
|
|
|
|
{
|
|
|
|
|
return PlayerManager.getPlayersInALobby(idLobby);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<int?> getMaxScorePlayer(int id, int idChapter)
|
|
|
|
|
{
|
|
|
|
|
return PlayerManager.getMaxScorePlayer(id, idChapter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<int?> getMaxScorePlayer(int id)
|
|
|
|
|
{
|
|
|
|
|
return PlayerManager.getMaxScorePlayer(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNbQuestions()
|
|
|
|
|
{
|
|
|
|
|
return QuestionManager.getNbQuestions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<QuestionDto> addQuestion(QuestionDto question)
|
|
|
|
|
{
|
|
|
|
|
return QuestionManager.addQuestion(question);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<QuestionDto?> removeQuestion(QuestionDto question)
|
|
|
|
|
{
|
|
|
|
|
return QuestionManager.removeQuestion(question);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<QuestionDto?> removeQuestion(int id)
|
|
|
|
|
{
|
|
|
|
|
return QuestionManager.removeQuestion(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<(int nbPages, IEnumerable<QuestionDto>? questions)> getQuestions(int nb, int count, QuestionOrderCriteria orderCriteria = QuestionOrderCriteria.ById)
|
|
|
|
|
{
|
|
|
|
|
return QuestionManager.getQuestions(nb, count, orderCriteria);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<QuestionDto?> getQuestion(int id)
|
|
|
|
|
{
|
|
|
|
|
return QuestionManager.getQuestion(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<QuestionDto?> updateQuestion(int id, QuestionDto question)
|
|
|
|
|
{
|
|
|
|
|
return QuestionManager.updateQuestion(id, question);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<QuestionDto?> updateQuestionNbFalls(int id)
|
|
|
|
|
{
|
|
|
|
|
return QuestionManager.updateQuestionNbFalls(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<IEnumerable<QuestionDto>> addQuestions(IEnumerable<QuestionDto> questions)
|
|
|
|
|
{
|
|
|
|
|
return QuestionManager.addQuestions(questions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<(int nbPages, IEnumerable<QuestionDto>? questions)?> getQuestionsByChapterAndDifficulty(int idChapter, int difficulty, int nb, int count, QuestionOrderCriteria orderCriteria = QuestionOrderCriteria.ById)
|
|
|
|
|
{
|
|
|
|
|
return QuestionManager.getQuestionsByChapterAndDifficulty(idChapter, difficulty, nb, count, orderCriteria);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|