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);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets news item from list with specified id with appropriate link relations
        /// </summary>
        /// <param name="id">Id associated with news item to fetch</param>
        /// <returns>A single news item by id or throws exception if not found</returns>
        public NewsItemDetailDto GetNewsItemById(int id)
        {
            var newsItem = _newsItemRepository.GetNewsItemById(id);

            if (newsItem == null)
            {
                throw new ResourceNotFoundException($"News item with id {id} was not found.");
            }
            newsItem.AddReferences(newsItem.Id, getCategories(newsItem.Id), getAuthors(newsItem.Id));
            return(newsItem);
        }
        public void GetNewsItemById_ShouldReturnNewsItemWithId1()
        {
            var newsItem = _repository.GetNewsItemById(1);

            Assert.AreEqual(newsItem.Id, 1);
        }