public void DeleteNewsItemById(int newsItemId)
        {
            var newsItem = _repo.GetNewsItemById(newsItemId);

            if (newsItem == null)
            {
                throw new ResourceNotFoundException($"News item with id {newsItemId} was not found.");
            }
            _repo.DeleteNewsItem(newsItem);
        }
Exemplo n.º 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);
            }
        }