コード例 #1
0
        public IEnumerable <AuthorDto> GetAllAuthors()
        {
            var authors = _authorRepository.GetAllAuthors().ToList();

            authors.ForEach(a => {
                a.Links.AddReference("self", $"api/authors/{a.Id}");
                a.Links.AddReference("edit", $"api/authors/{a.Id}");
                a.Links.AddReference("delete", $"api/authors/{a.Id}");
                a.Links.AddReference("newsItems", $"api/authors/{a.Id}/newsItems");
                a.Links.AddListReference("newsItemsDetailed", _newsItemRepository.GetNewsItemsByAuthorId(a.Id).Select(n => new { href = $"api/{n.Id}" }));
            });
            return(authors);
        }
コード例 #2
0
 private void AddLinksToAuthorDto(HyperMediaModel a, int Id)
 {
     a.Links.AddReference("self", new { href = $"/api/authors/{Id}" });
     a.Links.AddReference("edit", new { href = $"/api/authors/{Id}" });
     a.Links.AddReference("delete", new { href = $"/api/authors/{Id}" });
     a.Links.AddReference("newsItems", new { href = $"/api/authors/{Id}/newsItems" });
     a.Links.AddListReference("newsItemsDetailed",
                              _newsItemRepository.GetNewsItemsByAuthorId(Id).Select(n => new { href = $"/api/{n.Id}" }));
 }
コード例 #3
0
        public IEnumerable <NewsItemDto> GetNewsByAuthor(int id)
        {
            var news = _newsItemRepository.GetNewsItemsByAuthorId(id).ToList();

            if (news == null)
            {
                throw new ResourceNotFoundException($"News item with id {id} was not found. ");
            }
            news.ForEach(n =>
            {
                AddLinksToNewsItems(n, n.Id);
            });
            return(news);
        }