What is the proper way to structure DTO's for my tables?
Three of my tables are Documents which contains Pages and Fontstyles. I am creating an EditDocument view in which I will edit these (and more) tables related to document.
I thought of a solution, but I'm not sure if this is the proper way to do it. I'm just a beginner and just starting with dependency injection so, I might need some help on that too. what are your thoughts?
Create a List< fontStyleDTO > and List< PagesDTO > within DocumentDTO which contains the pages and fonts
public class DocumentDTO
{
public DocumentDTO (List<FontStyleDTO> fontStyles, List<PageDTO> pages) {
_fontStyles = fontStyles;
_pages = pages;
}
public List<FontStyleDTO> Pages {
get { return _pages; }
}
public List<PageDTO> FontStyles {
get { return _fontStyles; }
}
}
If I would want to add a page to the document I would do:
document.Pages.Add(page)
And then via the OR-mapper in the database:
public class DocumentDTOIntoDatabase
{
public DocumentDTOToDatabase (DTODocument document, DocumentMapper documentMapper) {
_document = document;
_documentMapper = documentMapper;
}
public AddDocumentToDatabase() {
Document ormDocument = _documentMapper.FindById(document.id)
ormDocument.name = document.name;
//etc...
AddPagesToDocument(document.pages, ormDocument)
ormDocument.save
}
public AddPagesToDocument(List<PageDTO> pages, Document ormDocument) {
foreach (var page in document.Pages) {
ormDocument.Pages.Add(convertToOrmPage(page))
}
}
}