Ejemplo n.º 1
0
        public List <NewsItemDto> GetAllNews()
        {
            var news = _newsRepo.GetAllNews();

            foreach (var n in news)
            {
                n.Links.AddReference("self", $"api/{n.Id}");
                n.Links.AddReference("edit", $"api/{n.Id}");
                n.Links.AddReference("delete", $"api/{n.Id}");
                n.Links.AddListReference("authors", _newsRepo.GetAuthorsByNewsItemId(n.Id)
                                         .Select(a => new { href = $"api/authors/{a.Id}" }));
                n.Links.AddListReference("categories", _newsRepo.GetCategoriesByNewsItemId(n.Id)
                                         .Select(c => new { href = $"api/categories/{c.Id}" }));
            }
            return(news);
        }