private AuthorDetailDto referenceItem(AuthorDetailDto item) { JObject tmpObj = new JObject(); // get all news items authors List <NewsAuthorRelation> authourRelList = _relationService.getRelationsByAuthorId(item.Id); tmpObj.TryAdd("href", "api/authors/" + item.Id); item.addReference("self", tmpObj); item.addReference("edit", tmpObj); item.addReference("delete", tmpObj); tmpObj.TryAdd("href", "api/authors/" + item.Id + "/newsItems"); item.addReference("newsItems", tmpObj); List <JObject> objList = new List <JObject>(); foreach (NewsAuthorRelation relation in authourRelList) { JObject relObj = new JObject(); relObj.TryAdd("href", "api/" + relation.newsId); objList.Add(relObj); } item.addReference("newsItemsDetailed", objList); return(item); }
private AuthorDetailDto AddAuthorDetailDtoLinks(AuthorDetailDto author) { author.Links.AddReference("edit", $"api/authors/{author.Id}"); author.Links.AddReference("delete", $"api/authors/{author.Id}"); author.Links.AddReference("self", $"api/authors"); author.Links.AddReference("newsItems", $"api/authors/{author.Id}/newsItems"); author.Links.AddListReference("newsItemsDetailed", _authorRepo.GetNewsItemsByAuthor(author.Id) .Select(n => new { href = $"api/{n.Id}" })); return(author); }
public static void AddReferences(this AuthorDetailDto item, int Id, IEnumerable <AuthorNewsItemRelation> newsItems) { item.AddAuthorReferences(Id, newsItems); }
public ActionResult <string> getAuthorById(int authorId) { AuthorDetailDto author = _authorService.getAuthorById(authorId); return(Ok(referenceItem(author))); }