Ejemplo n.º 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);
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
        }