private string CreateCollectionPropertyResourceUri( string collection, WebApiPagedRequestDto resourceParameters, ResourceUriType type) { switch (type) { case ResourceUriType.PreviousPage: return(Url.Action(nameof(BulkGetByIds), Url.ActionContext.RouteData.Values["controller"].ToString(), new { collection = collection, fields = resourceParameters.Fields, page = resourceParameters.Page - 1, pageSize = resourceParameters.PageSize }, Url.ActionContext.HttpContext.Request.Scheme)); case ResourceUriType.NextPage: return(Url.Action(nameof(BulkGetByIds), Url.ActionContext.RouteData.Values["controller"].ToString(), new { collection = collection, fields = resourceParameters.Fields, page = resourceParameters.Page + 1, pageSize = resourceParameters.PageSize }, Url.ActionContext.HttpContext.Request.Scheme)); default: return(Url.Action(nameof(BulkGetByIds), Url.ActionContext.RouteData.Values["controller"].ToString(), new { collection = collection, fields = resourceParameters.Fields, page = resourceParameters.Page, pageSize = resourceParameters.PageSize }, Url.ActionContext.HttpContext.Request.Scheme)); } }
/// <summary> /// Creates the links for collection property. /// </summary> /// <param name="collection">The collection.</param> /// <param name="resourceParameters">The resource parameters.</param> /// <param name="hasNext">if set to <c>true</c> [has next].</param> /// <param name="hasPrevious">if set to <c>true</c> [has previous].</param> /// <returns></returns> private IEnumerable<LinkDto> CreateLinksForCollectionProperty(string collection, WebApiPagedRequestDto resourceParameters, bool hasNext, bool hasPrevious) { var links = new List<LinkDto>(); // self links.Add( new LinkDto(CreateCollectionPropertyResourceUri(collection, resourceParameters, ResourceUriType.Current) , "self", HttpMethod.Get.Method)); //Todo if want to allow Add to collection property // links.Add( // new LinkDto(UrlHelper.Action("Create", UrlHelper.ActionContext.RouteData.Values["controller"].ToString(), //null, UrlHelper.ActionContext.HttpContext.Request.Scheme), // "add", // "POST")); if (hasNext) { links.Add( new LinkDto(CreateCollectionPropertyResourceUri(collection, resourceParameters, ResourceUriType.NextPage), "nextPage", HttpMethod.Get.Method)); } if (hasPrevious) { links.Add( new LinkDto(CreateCollectionPropertyResourceUri(collection, resourceParameters, ResourceUriType.PreviousPage), "previousPage", HttpMethod.Get.Method)); } return links; }