Exemplo n.º 1
0
        public async Task <Node> GetBySlugAsync(
            string module,
            string type,
            string slug,
            bool noStore = false)
        {
            var nodeSearch = new NodeSearch()
            {
                Module = module,
                Type   = type,
                Slug   = slug
            };
            var requestUri = $"{API_URL}/GetPaginatedResult?{nodeSearch.ToQueryString()}";

            using var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
            if (noStore)
            {
                request.SetBrowserRequestCache(BrowserRequestCache.NoStore);
            }
            var response = await PublicHttpClient.SendAsync(request);

            if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                return(null);
            }
            var jsonString = await response.Content.ReadAsStringAsync();

            var items = System.Text.Json.JsonSerializer.Deserialize <Node[]>(jsonString, _jsonSerializerOptions);

            return(items.FirstOrDefault());
        }
Exemplo n.º 2
0
        public async Task <int> GetCountAsync(NodeSearch nodeSearch)
        {
            var request  = $"{API_URL}/GetCount?{nodeSearch.ToQueryString()}";
            var response = await PublicHttpClient.GetAsync(request);

            var count = await response.Content.ReadAsStringAsync();

            return(int.Parse(count));
        }
Exemplo n.º 3
0
        public async Task <Node[]> SecureGetAsync(
            NodeSearch nodeSearch,
            int currentPage)
        {
            var request  = $"{API_URL}/GetPaginatedResult?currentPage={currentPage}&{nodeSearch.ToQueryString()}";
            var response = await AuthorizedHttpClient.GetAsync(request);

            var jsonString = await response.Content.ReadAsStringAsync();

            return(System.Text.Json.JsonSerializer.Deserialize <Node[]>(jsonString, _jsonSerializerOptions));
        }
Exemplo n.º 4
0
        public async Task <int> GetPageSizeAsync(NodeSearch nodeSearch)
        {
            var request  = $"{API_URL}/GetPageSize?{nodeSearch.ToQueryString()}";
            var response = await PublicHttpClient.GetAsync(request);

            var pageSize = await response.Content.ReadAsStringAsync();

            int result;

            int.TryParse(pageSize, out result);
            return(result);
        }
Exemplo n.º 5
0
        public async Task <Node> SecureGetAsync(
            string module,
            string type,
            string slug)
        {
            var nodeSearch = new NodeSearch()
            {
                Module = module,
                Type   = type,
                Slug   = slug
            };
            var request  = $"{API_URL}/GetPaginatedResult?{nodeSearch.ToQueryString()}";
            var response = await AuthorizedHttpClient.GetAsync(request);

            var jsonString = await response.Content.ReadAsStringAsync();

            var items = System.Text.Json.JsonSerializer.Deserialize <Node[]>(jsonString, _jsonSerializerOptions);

            return(items.FirstOrDefault());
        }