public bool IsAllowedToUpdateText(string loggedUserEmail, Guid textToUpdateId) { bool isAllowed = false; IsValidUser(loggedUserEmail); if (TextRepository.Exists(textToUpdateId)) { Text text = TextRepository.GetById(textToUpdateId); Content content = ContentRepository.GetByText(new Text { Id = textToUpdateId }); bool headerWithThatContent = HeaderRepository.ExistsWithContent(content); bool footerWithThatContent = FooterRepository.ExistsWithContent(content); bool paragraphWithThatContent = ParagraphRepository.ExistsWithContent(content); if (headerWithThatContent == true) { Header header = HeaderRepository.GetByContent(content); Document document = DocumentRepository.GetById(header.DocumentThatBelongs.Id); User user = document.Creator; isAllowed = user.Email == loggedUserEmail; } else if (footerWithThatContent == true) { Footer footer = FooterRepository.GetByContent(content); Document document = DocumentRepository.GetById(footer.DocumentThatBelongs.Id); User user = document.Creator; isAllowed = user.Email == loggedUserEmail; } else if (paragraphWithThatContent == true) { Paragraph paragraph = ParagraphRepository.GetByContent(content); Document document = DocumentRepository.GetById(paragraph.DocumentThatBelongs.Id); User user = document.Creator; isAllowed = user.Email == loggedUserEmail; } } return(isAllowed); }