Пример #1
0
        private HateoasCollectionView GetHateoasCollectionView(CollectionView output)
        {
            string parentResourceCode  = CurrentEndpoint.ResourceCode;
            string currentResourceCode = output.ResourceCode;

            var collectionLinks   = GetCollectionLinks(currentResourceCode, output);
            var collectionActions = GetCollectionActions(currentResourceCode);

            List <HateoasElementView> embeddedList = new List <HateoasElementView>();

            foreach (var element in output.ViewModels)
            {
                HateoasElementView elementView = GetHateoasElementView(element);
                embeddedList.Add(elementView);
            }

            HateoasLabeledLink parentLink = this.GetParentLink(parentResourceCode, currentResourceCode);

            int totalExisting       = output.TotalExisting;
            int totalPagesAvailable = (int)Math.Ceiling((double)totalExisting / output.UsedFilter.PageSize.Values.First());

            var allFiltersUsed = this.GetCollectionFilteringMap(output.UsedFilter);

            var collectionView = new HateoasCollectionView(totalExisting, totalPagesAvailable, allFiltersUsed, collectionLinks, collectionActions, embeddedList, parentLink);

            return(collectionView);
        }
Пример #2
0
 public HateoasObject(
     Dictionary <string, string> collectionLinks,
     Dictionary <string, HateoasAction> collectionActions,
     IEnumerable <object> embeddedList,
     HateoasLabeledLink parentLink = null)
 {
     this._links    = collectionLinks;
     this._actions  = collectionActions;
     this._embedded = embeddedList;
     this._parent   = parentLink;
 }
Пример #3
0
        public HateoasElementView(
            Dictionary <string, string> elementLinks,
            Dictionary <string, HateoasAction> elementActions,
            object element,
            HateoasLabeledLink parentLink = null)
        {
            this._links    = elementLinks;
            this._actions  = elementActions;
            this._embedded = element;

            this._parent = parentLink;
        }
Пример #4
0
        public HateoasElementView GetHateoasElementView(IApiResource resource)
        {
            string             parentResourceCode = CurrentEndpoint.ResourceCode;
            HateoasLabeledLink parentLink         = this.GetParentLink(parentResourceCode, resource.ApiResourceCode);

            var elemLinks   = GetElementLinks(resource);
            var elemActions = GetElementActions(resource);

            var view = new HateoasElementView(elemLinks, elemActions, resource, parentLink);

            return(view);
        }
Пример #5
0
        public HateoasCollectionView(
            int totalElementsAvailable,
            int totalPages,
            Dictionary <string, object> filtersUsed,
            Dictionary <string, string> collectionLinks,
            Dictionary <string, HateoasAction> collectionActions,
            IEnumerable <object> embeddedList,
            HateoasLabeledLink parentLink = null)
            : base(collectionLinks, collectionActions, embeddedList, parentLink)
        {
            this.Total      = totalElementsAvailable;
            this.TotalPages = totalPages;

            _filter = filtersUsed;
        }
Пример #6
0
        private HateoasLabeledLink GetParentLink(string parentResourceCode, string childResourceCode)
        {
            HateoasLabeledLink parentLink = null;

            if (childResourceCode != parentResourceCode)
            {
                Endpoint parentGetter     = HateoasService.GetElementGetter(parentResourceCode);
                object   getterParamValue = ProvidedActionArguments[parentGetter.GetterParameterName];

                string parentUrl = HateoasService.GetElementGetterUrl(parentResourceCode, parentGetter.GetterParameterName, getterParamValue);
                parentLink = new HateoasLabeledLink(parentGetter.DisplayNameWhenLinked, parentUrl);
            }

            return(parentLink);
        }