Exemplo n.º 1
0
        public static void AddPaginationHeader(this HttpResponse response, int currentPage, int itemsPerPage, int totalItems, int totalPages)
        {
            var options = new JsonSerializerOptions
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            };

            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            response.Headers.Add("Pagination", JsonSerializer.Serialize(paginationHeader, options));
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
Exemplo n.º 2
0
        public static void AddPaginationHeader(this HttpResponse response, int currentPage, int itemsPerPage,
                                               int totalItems, int totalPages)
        {
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            var settings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader, settings));
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
        public static void AddPaginationHeaders(this HttpResponse response, int pageNumber, int totalPages,
                                                int pageSize, int totalCount)
        {
            var paginationHeader = new PaginationHeader(pageNumber, totalPages, pageSize, totalCount);

            var options = new JsonSerializerOptions()
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            };

            response.Headers.Add("X-Pagination", JsonSerializer.Serialize <PaginationHeader>(paginationHeader, options));
            response.Headers.Add("Access-Control-Expose-Headers", "X-Pagination");
        }
Exemplo n.º 4
0
        public static void AddPaginationHeader(this HttpResponse response, int pageNumber, int itemsPerPage,
                                               int totalPages, int totalItems)
        {
            PaginationHeader paginationHeader = new PaginationHeader(pageNumber, itemsPerPage, totalPages, totalItems);
            // API response which is in PascalCase will be converted to JSON camelCase by default
            // But will not be converted while adding headers, so converting it to camelCase using the options
            var options = new JsonSerializerOptions
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            };

            response.Headers.Add("Pagination", JsonSerializer.Serialize(paginationHeader, options));
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
Exemplo n.º 5
0
        public static void AddPaginationHeader(this HttpResponse response, int currentPage, int itemsPerPage, int totalItems, int totalPages)
        {
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            var options = new JsonSerializerOptions
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            };

            response.Headers.Add("Pagination", JsonSerializer.Serialize(paginationHeader, options));

            // If you want clients to be able to access other headers, you have to list them using the Access-Control-Expose-Headers header.
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination"); // A-C-E-H should be correct
        }
Exemplo n.º 6
0
        public static void AddPaginationHeader(this HttpResponse httpResponse, int pageNumber, int pageSize, int totalCount, int totalPages)
        {
            const string paginationHeaderName = "Pagination";

            var paginationHeader = new PaginationHeader(pageNumber, pageSize, totalCount, totalPages);

            var options = new JsonSerializerOptions
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            };

            httpResponse.Headers.Add(paginationHeaderName, JsonSerializer.Serialize(paginationHeader, options));
            httpResponse.Headers.Add("Access-Control-Expose-Headers", paginationHeaderName);
        }
Exemplo n.º 7
0
        public static void AddPaginationHeader(this HttpResponse response, int currentPage, int itemsPerPage, int totalItems, int totalPages)
        {
            // pass props in same order as helper expects
            var PaginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            var options = new JsonSerializerOptions {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            };

            // custom header
            response.Headers.Add("Pagination", JsonSerializer.Serialize(PaginationHeader, options));

            // cors
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
Exemplo n.º 8
0
        public static void AddPagination(this HttpResponse response,
                                         int currentPage, int itemsPerPage, int totalItems, int totalPages)
        {
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            var options = new JsonSerializerOptions {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            };

            var json = JsonSerializer.Serialize(paginationHeader, options);

            // var camelCaseFormatter = new JsonSerializerSettings();
            //camelCaseFormatter.ContractResolver = new CamelCasePropertyNamesContractResolver();
            response.Headers.Add("Pagination", json);
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
Exemplo n.º 9
0
        public static void AddPaginationHeader(this HttpResponse response, int currentPage, int itemsPerPage, int totalItems, int totalPages)
        {
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            // Make header camelCase instead TitleCase for client app
            var options = new JsonSerializerOptions
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            };

            // Add custom header
            response.Headers.Add("Pagination", JsonSerializer.Serialize(paginationHeader, options));

            // Add CORS header to pagination header to make available
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
Exemplo n.º 10
0
        public static void AddPaginationHeader(
            this HttpResponse response,
            int currentPage, int itemsPerPage,
            int totalItems, int totalPages)
        {
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);
            var options          = new JsonSerializerOptions // option for making json camel case
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            };

            response.Headers.Add("Pagination", JsonSerializer.Serialize(paginationHeader, options));
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
            // pagination : ten tu dat
            // Access-control-... : phai viet chinh xac nhu vay
        }
Exemplo n.º 11
0
    {                                                                                                                                         // we will create our method to return header in here
        public static void AddPaginationHeader(this HttpResponse response, int currentPage, int itemsPerPage, int totalItems, int totalPages) // our PaginationHeader variables
        {
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);                                   // this is our header

            var options = new JsonSerializerOptions
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase                                       // added this option to convert our header form title case to camel case
            };

            response.Headers.Add("Pagination", JsonSerializer.Serialize(paginationHeader, options));
            // only req. here is to give our header a sensible name // we then need to searialise the header as it contains a reponse, key
            // options added here after working through pagination code .. var options added to convert case

            // we need to add a cause header to make "Pagination" header available // we do this below
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination"); // these two variables need to match exactly, exat string matches
            // we then create a new class to receive the pagination parameters from the user
        }
Exemplo n.º 12
0
        public static void AddPaginationHeader(
            this HttpResponse response,
            int currentPage,
            int itemsPerPage,
            int totalItems,
            int totalPages
            )
        {
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            // Create an options variable to send the headers back as CamelCase
            var options = new JsonSerializerOptions {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            };

            // Create the Header by serializing the PaginationHeader to JSON
            // Access-Control-Expose-Headers is also required for the custom header to be displayed
            response.Headers.Add("Pagination", JsonSerializer.Serialize(paginationHeader, options));
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
Exemplo n.º 13
0
        public static void AddPaginationHeader(this HttpResponse response,
                                               int currentPage, int itemsPerPage, int totalItems, int totalPages
                                               )
        {
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            var opt = new JsonSerializerOptions()
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            };

            response.Headers.Add("Pagination", JsonSerializer.Serialize(paginationHeader, opt));
            // Access-Control-Expose-Headers (optional) - The XMLHttpRequest 2 object has a getResponseHeader() method that returns the value of a particular response header. During a CORS request, the getResponseHeader() method can only access simple response headers. Simple response headers are defined as follows:
            // Cache-Control
            // Content-Language
            // Content-Type
            // Expires
            // Last-Modified
            // Pragma
            // If you want clients to be able to access other headers, you have to use the Access-Control-Expose-Headers header. The value of this header is a comma-delimited list of response headers you want to expose to the client.
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }