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.");
     }
 }
        public Header Add(Guid documentId, Header header)
        {
            if (DocumentRepository.Exists(documentId))
            {
                if (!HeaderRepository.ExistsForDocument(documentId))
                {
                    Document documentThatBelongs = DocumentRepository.GetById(documentId);
                    documentThatBelongs.StyleClass = null;

                    header.DocumentThatBelongs = documentThatBelongs;

                    header.Id = Guid.NewGuid();

                    header.Content = new Content()
                    {
                        Id = Guid.NewGuid()
                    };

                    if (header.StyleClass != null && !StyleClassRepository.Exists(header.StyleClass.Name))
                    {
                        header.StyleClass = null;
                    }

                    ContentRepository.Add(header.Content);
                    HeaderRepository.Add(header);

                    return(header);
                }
                else
                {
                    throw new ExistingHeaderException("This document already has a header.");
                }
            }
            else
            {
                throw new MissingDocumentException("This document is not in 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);
        }