public Header GetByDocument(Guid documentId)
 {
     if (DocumentRepository.Exists(documentId))
     {
         if (HeaderRepository.ExistsForDocument(documentId))
         {
             return(HeaderRepository.GetByDocument(documentId));
         }
         else
         {
             throw new MissingHeaderException("This header is not in the database");
         }
     }
     else
     {
         throw new MissingDocumentException("This document is not on the database.");
     }
 }
        private string ApplyDocumentStyle(Document document, Format format)
        {
            IEnumerable <Style> currentStyles = GetStylesWithInheritance(document.StyleClass, format);

            string appliedHtmlCode = "";

            if (!HeaderRepository.ExistsForDocument(document.Id) && !FooterRepository.ExistsForDocument(document.Id))
            {
                appliedHtmlCode = "" + ApplyParagraphStyles(ParagraphRepository.GetAllByDocument(document.Id), format, currentStyles);
            }
            else if (!FooterRepository.ExistsForDocument(document.Id))
            {
                appliedHtmlCode = "" + ApplyHeaderStyle(HeaderRepository.GetByDocument(document.Id), format, currentStyles)
                                  + "<br>" + ApplyParagraphStyles(ParagraphRepository.GetAllByDocument(document.Id), format, currentStyles);
            }
            else
            {
                appliedHtmlCode = "" + ApplyHeaderStyle(HeaderRepository.GetByDocument(document.Id), format, currentStyles)
                                  + "<br>" + ApplyParagraphStyles(ParagraphRepository.GetAllByDocument(document.Id), format, currentStyles)
                                  + "<br>" + ApplyFooterStyles(FooterRepository.GetByDocument(document.Id), format, currentStyles);
            }

            return(appliedHtmlCode);
        }