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); }
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; }
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; }
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); }
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; }
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); }