示例#1
0
 public void Update(Guid textId, Text newTextData)
 {
     if (TextRepository.Exists(textId))
     {
         Text textToUpdate = TextRepository.GetById(textId);
         if (textToUpdate.Position != newTextData.Position)
         {
             IEnumerable <Text> textsInContent = TextRepository.GetByContent(textToUpdate.ContentThatBelongs);
             int newPosition = newTextData.Position;
             int maxPosition = textsInContent.Count() - 1;
             if (newPosition > maxPosition || newPosition < 0)
             {
                 throw new InvalidPositionException("This position is not valid for the content in question.");
             }
             else
             {
                 Text swappedText = textsInContent.First(p => p.Position == newPosition);
                 swappedText.Position = textToUpdate.Position;
                 TextRepository.Update(swappedText);
                 textToUpdate.Position = newPosition;
             }
         }
         if (newTextData.StyleClass != null && !StyleClassRepository.Exists(newTextData.StyleClass.Name))
         {
             newTextData.StyleClass = null;
         }
         textToUpdate.StyleClass  = newTextData.StyleClass;
         textToUpdate.TextContent = newTextData.TextContent;
         TextRepository.Update(textToUpdate);
     }
     else
     {
         throw new MissingParagraphException("This paragraph is not in the database.");
     }
 }
 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.");
     }
 }
示例#3
0
 public Text GetById(Guid textId)
 {
     if (TextRepository.Exists(textId))
     {
         return(TextRepository.GetById(textId));
     }
     else
     {
         throw new MissingTextException("This text is not in the database.");
     }
 }
示例#4
0
 public void Delete(Guid textId)
 {
     if (TextRepository.Exists(textId))
     {
         Text textToDelete = TextRepository.GetById(textId);
         IEnumerable <Text> textsInContent = TextRepository.GetByContent(textToDelete.ContentThatBelongs);
         foreach (Text textInContent in textsInContent)
         {
             if (textInContent.Position > textToDelete.Position)
             {
                 textInContent.Position--;
                 TextRepository.Update(textInContent);
             }
         }
         TextRepository.Delete(textId);
     }
     else
     {
         throw new MissingTextException("This text is not in the database");
     }
 }