Ejemplo n.º 1
0
        private NewsItemDto referenceLightItem(NewsItemDto 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);
        }