public Footer Add(Guid documentId, Footer footer) { if (DocumentRepository.Exists(documentId)) { if (!FooterRepository.ExistsForDocument(documentId)) { Document documentThatBelongs = DocumentRepository.GetById(documentId); documentThatBelongs.StyleClass = null; footer.DocumentThatBelongs = documentThatBelongs; footer.Id = Guid.NewGuid(); footer.Content = new Content() { Id = Guid.NewGuid() }; if (footer.StyleClass != null && !StyleClassRepository.Exists(footer.StyleClass.Name)) { footer.StyleClass = null; } ContentRepository.Add(footer.Content); FooterRepository.Add(footer); return(footer); } else { throw new ExistingFooterException("This document already has a footer."); } } else { throw new MissingDocumentException("This document is not in the database."); } }