private static NewsItemDetailDto NewsItemDetailHelper(NewsItemDetailDto NewsDetail, List <ExpandoObject> NewsCategories, List <ExpandoObject> NewsAuthors, int id) { dynamic objSelf = new ExpandoObject(); dynamic objEdit = new ExpandoObject(); dynamic objDelete = new ExpandoObject(); objSelf.href = objDelete.href = objEdit.href = "api/" + id; HyperAddHelper(NewsDetail.Links, objSelf, objEdit, objDelete, NewsAuthors, NewsCategories); return(NewsDetail); }
public ActionResult <string> getNewsItemById(int id) { NewsItemDetailDto item = _newsItemService.getNewsItemById(id); if (item == null) { throw new ResourceNotFoundException(); } return(Ok(referenceItem(item))); }
public IActionResult GetNewsById(int id) { NewsItemDetailDto NewsDetail = _trService.GetNewsById(id); var TmpList = Enumerable.Repeat(NewsDetail, 1); IEnumerable <NewsItemCategories> NewsCategories = _trService.GetNewsCategoriesById(id); IEnumerable <NewsItemAuthors> NewsAuthors = _trService.GetNewsAuthorsById(id); List <ExpandoObject> FilteredNewsCategories = FilerCategories(NewsCategories, id); List <ExpandoObject> FilteredNewsAuthors = FilterAuthors(NewsAuthors, id); return(Ok(NewsItemDetailHelper(NewsDetail, FilteredNewsCategories, FilteredNewsAuthors, id))); }
private NewsItemDetailDto referenceItem(NewsItemDetailDto item) { JObject tmpObj = new JObject(); // get all news items authors List <NewsAuthorRelation> authourRelList = _relationService.getAutherNewsRelationByNewsId(item.Id); // get all news items categories List <NewsCategoryRelation> categoryRelList = _relationService.getNewsCateoryRelationByNewsId(item.Id); tmpObj.TryAdd("href", "api/" + item.Id); item.addReference("self", tmpObj); item.addReference("edit", tmpObj); item.addReference("delete", tmpObj); List <JObject> aObjList = new List <JObject>(); foreach (NewsAuthorRelation aItem in authourRelList) { JObject authorObject = new JObject(); authorObject.TryAdd("href", "api/authors/" + aItem.authorId); aObjList.Add(authorObject); } item.addReference("authors", aObjList); List <JObject> cObjList = new List <JObject>(); foreach (NewsCategoryRelation cItem in categoryRelList) { JObject catObject = new JObject(); catObject.TryAdd("href", "api/categories/" + cItem.categoryId); cObjList.Add(catObject); } item.addReference("categories", cObjList); return(item); }
public static void AddReferences(this NewsItemDetailDto item, int Id, IEnumerable <NewsItemCategoryRelation> categoryRelations, IEnumerable <AuthorNewsItemRelation> authorRelations) { item.AddNewsItemReferences(Id, categoryRelations, authorRelations); }