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.
71 lines
2.2 KiB
71 lines
2.2 KiB
using DbConnectionLibrairie;
|
|
using DataManagers;
|
|
using ExtensionsClassLibrairie;
|
|
using ManagerInterfaces;
|
|
using Model;
|
|
using OrderCriterias;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using DTOs;
|
|
|
|
namespace ServiceManagers
|
|
{
|
|
public class ChapterServiceManager(IChapterManager<Chapter> manager) : IChapterManager<ChapterDto>
|
|
{
|
|
private IChapterManager<Chapter> manager = manager;
|
|
|
|
public async Task<ChapterDto> addChapter(ChapterDto chapterdto)
|
|
{
|
|
return await Task.FromResult<ChapterDto>((await manager.addChapter(chapterdto.ToModel())).ToDto());
|
|
}
|
|
|
|
public async Task<ChapterDto?> getChapter(int id)
|
|
{
|
|
return await Task.FromResult<ChapterDto?>((await manager.getChapter(id))?.ToDto());
|
|
}
|
|
|
|
public async Task<ChapterDto?> getChapter(string name)
|
|
{
|
|
return (await manager.getChapter(name))?.ToDto();
|
|
}
|
|
|
|
public async Task<(int nbPages, IEnumerable<ChapterDto>? chapters)> getChapters(int nb, int count, ChapterOrderCriteria orderCriteria = ChapterOrderCriteria.ById)
|
|
{
|
|
List<ChapterDto>? tmp = new List<ChapterDto>();
|
|
var res = await manager.getChapters(nb, count, orderCriteria);
|
|
if (res.chapters == null) tmp = null;
|
|
else
|
|
{
|
|
foreach (var item in res.chapters)
|
|
{
|
|
tmp.Add(item.ToDto());
|
|
}
|
|
}
|
|
return await Task.FromResult<(int nbPages, IEnumerable<ChapterDto>? chapters)>((res.nbPages, tmp));
|
|
}
|
|
|
|
public int getNbChapters()
|
|
{
|
|
return manager.getNbChapters();
|
|
}
|
|
|
|
public async Task<ChapterDto?> removeChapter(ChapterDto chapterdto)
|
|
{
|
|
return (await manager.removeChapter(chapterdto.ToModel()))?.ToDto();
|
|
}
|
|
|
|
public async Task<ChapterDto?> removeChapter(int id)
|
|
{
|
|
return (await manager.removeChapter(id))?.ToDto();
|
|
}
|
|
|
|
public async Task<ChapterDto?> updateChapter(int id, string newName)
|
|
{
|
|
return (await manager.updateChapter(id, newName))?.ToDto();
|
|
}
|
|
}
|
|
}
|