public void LogModificationToText(Guid textId)
 {
     if (TextRepository.Exists(textId))
     {
         Text    textOfModdedDocument    = TextRepository.GetById(textId);
         Content contentOfModdedDocument = textOfModdedDocument.ContentThatBelongs;
         if (HeaderRepository.ExistsWithContent(contentOfModdedDocument))
         {
             Header headerOfModdedDocument = HeaderRepository.GetByContent(contentOfModdedDocument);
             LogModificationToDocument(headerOfModdedDocument.DocumentThatBelongs.Id);
         }
         else if (ParagraphRepository.ExistsWithContent(contentOfModdedDocument))
         {
             Paragraph paragraphOfModdedDocument = ParagraphRepository.GetByContent(contentOfModdedDocument);
             LogModificationToDocument(paragraphOfModdedDocument.DocumentThatBelongs.Id);
         }
         else if (FooterRepository.ExistsWithContent(contentOfModdedDocument))
         {
             Footer footerOfModdedDocument = FooterRepository.GetByContent(contentOfModdedDocument);
             LogModificationToDocument(footerOfModdedDocument.DocumentThatBelongs.Id);
         }
     }
     else
     {
         throw new MissingTextException("This text is not in the database.");
     }
 }
 public void Update(Guid paragraphId, Paragraph newParagraphData)
 {
     if (ParagraphRepository.Exists(paragraphId))
     {
         Paragraph paragraphToUpdate = ParagraphRepository.GetById(paragraphId);
         if (paragraphToUpdate.Position != newParagraphData.Position)
         {
             IEnumerable <Paragraph> paragraphsInDocument = ParagraphRepository.GetAllByDocument(paragraphToUpdate.DocumentThatBelongs.Id);
             int newPosition = newParagraphData.Position;
             int maxPosition = paragraphsInDocument.Count() - 1;
             if (newPosition > maxPosition || newPosition < 0)
             {
                 throw new InvalidPositionException("This position is not valid for the document in question.");
             }
             else
             {
                 Paragraph swappedParagraph = paragraphsInDocument.First(p => p.Position == newPosition);
                 swappedParagraph.Position = paragraphToUpdate.Position;
                 ParagraphRepository.Update(swappedParagraph);
                 paragraphToUpdate.Position = newPosition;
             }
         }
         if (newParagraphData.StyleClass != null && !StyleClassRepository.Exists(newParagraphData.StyleClass.Name))
         {
             newParagraphData.StyleClass = null;
         }
         paragraphToUpdate.StyleClass = newParagraphData.StyleClass;
         ParagraphRepository.Update(paragraphToUpdate);
     }
     else
     {
         throw new MissingParagraphException("This paragraph is not in the database.");
     }
 }
 public IEnumerable <Paragraph> GetAllByDocument(Guid documentId)
 {
     if (DocumentRepository.Exists(documentId))
     {
         return(ParagraphRepository.GetAllByDocument(documentId));
     }
     else
     {
         throw new MissingDocumentException("The document doesn't exist in the database.");
     }
 }
 public void LogModificationToParagraph(Guid paragraphId)
 {
     if (ParagraphRepository.Exists(paragraphId))
     {
         Paragraph paragraphOfModdedDocument = ParagraphRepository.GetById(paragraphId);
         LogModificationToDocument(paragraphOfModdedDocument.DocumentThatBelongs.Id);
     }
     else
     {
         throw new MissingParagraphException("This paragraph is not in the database.");
     }
 }
Пример #5
0
 public IEnumerable <Text> GetAllByParagraph(Guid paragraphId)
 {
     if (ParagraphRepository.Exists(paragraphId))
     {
         Paragraph          paragraphForText     = ParagraphRepository.GetById(paragraphId);
         Content            contentFromParagraph = paragraphForText.Content;
         IEnumerable <Text> paragraphTexts       = TextRepository.GetByContent(contentFromParagraph);
         return(paragraphTexts);
     }
     else
     {
         throw new MissingParagraphException("The paragraph is not in the database.");
     }
 }
 public void Delete(Guid paragraphId)
 {
     if (ParagraphRepository.Exists(paragraphId))
     {
         Paragraph paragraphToDelete = ParagraphRepository.GetById(paragraphId);
         IEnumerable <Paragraph> paragraphsInDocument = ParagraphRepository.GetAllByDocument(paragraphToDelete.DocumentThatBelongs.Id);
         foreach (Paragraph paragraphInDocument in paragraphsInDocument)
         {
             if (paragraphInDocument.Position > paragraphToDelete.Position)
             {
                 paragraphInDocument.Position--;
                 ParagraphRepository.Update(paragraphInDocument);
             }
         }
         ParagraphRepository.Delete(paragraphId);
     }
     else
     {
         throw new MissingParagraphException("This paragraph is not in the database");
     }
 }
Пример #7
0
        public Text AddToParagraph(Guid paragraphId, Text text)
        {
            if (ParagraphRepository.Exists(paragraphId))
            {
                Paragraph paragraph = ParagraphRepository.GetById(paragraphId);
                paragraph.StyleClass = null;

                Paragraph paragraphForText = paragraph;

                Content            contentOfParagraph = paragraphForText.Content;
                IEnumerable <Text> paragraphTexts     = TextRepository.GetByContent(contentOfParagraph);
                text.Id                 = Guid.NewGuid();
                text.Position           = paragraphTexts.Count();
                text.ContentThatBelongs = contentOfParagraph;
                TextRepository.Add(text);

                return(text);
            }
            else
            {
                throw new MissingParagraphException("This paragraph does not exist in the database");
            }
        }
        public Paragraph Add(Guid documentId, Paragraph paragraph)
        {
            if (DocumentRepository.Exists(documentId))
            {
                Document documentThatBelongs = DocumentRepository.GetById(documentId);
                documentThatBelongs.StyleClass = null;

                paragraph.DocumentThatBelongs = documentThatBelongs;

                paragraph.Id = Guid.NewGuid();

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

                IEnumerable <Paragraph> existingParagraphs = ParagraphRepository.GetAllByDocument(documentId);
                int newMaxPosition = existingParagraphs.Count();

                paragraph.Position = newMaxPosition;

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

                ContentRepository.Add(paragraph.Content);
                ParagraphRepository.Add(paragraph);

                return(paragraph);
            }
            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);
        }