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 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.");
     }
 }
Example #3
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");
     }
 }
Example #5
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");
            }
        }