コード例 #1
0
ファイル: AuthorService.cs プロジェクト: laufey92/T-514-VEFT
        /// <summary>
        /// Deletes author by id
        /// </summary>
        /// <param name="id">id of author to delete</param>
        public void DeleteAuthorById(int id)
        {
            // Check if author exists, if it does delete him or her from list
            var author = _authorRepository.GetAuthorById(id);

            if (author == null)
            {
                throw new ResourceNotFoundException($"Author with id {id} was not found.");
            }
            _authorRepository.DeleteAuthorById(id);

            // delete all relations from list associated with news item
            var newsItemRelations = _newsItemRelationRepository.GetAllNewsItemsForAuthor(id).ToList();

            foreach (var relation in newsItemRelations)
            {
                _newsItemRelationRepository.DeleteRelation(relation);
            }
        }
コード例 #2
0
        /// <summary>
        /// Deletes news item by id
        /// </summary>
        /// <param name="id">id of news item to delete</param>
        public void DeleteNewsItemById(int id)
        {
            // Check if news item exist, if it does delete it
            var newsItem = _newsItemRepository.GetNewsItemById(id);

            if (newsItem == null)
            {
                throw new ResourceNotFoundException($"News item with id {id} was not found.");
            }
            _newsItemRepository.DeleteNewsItem(id);

            // delete all relations from list associated with news item
            var categoryRelations = _categoryRelationRepository.GetAllNewsItemsCategoryRelationsByNewsItemId(id).ToList();
            var authorRelations   = _authorRelationRepository.GetAuthorsForNewsItems(id).ToList();

            foreach (var relation in categoryRelations)
            {
                 _categoryRelationRepository.DeleteRelation(relation);
            }
            foreach (var relation in authorRelations)
            {
                _authorRelationRepository.DeleteRelation(relation);
            }
        }