예제 #1
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 camelCaseFormatter = new JsonSerializerSettings();

            camelCaseFormatter.ContractResolver = new CamelCasePropertyNamesContractResolver();

            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader,
                                                                           camelCaseFormatter));
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
예제 #2
0
        /// <summary>
        /// Header for pagination: data must be returned in camelCase for Angular works in camelCase
        /// </summary>
        /// <param name="Response"></param>
        /// <param name="CurrentPage"></param>
        /// <param name="ItemsPerPage"></param>
        /// <param name="TotalItems"></param>
        /// <param name="TotalPages"></param>
        public static void AddPagination(this HttpResponse Response, int CurrentPage, int ItemsPerPage, int TotalItems, int TotalPages)
        {
            var paginationHeader = new PaginationHeader(CurrentPage, ItemsPerPage, TotalItems, TotalPages);

            //USED TO RETURN DATA IN camelCase for JavaScript
            //CurrentPage => currentPage, etc.
            var camelCaseFormatter = new JsonSerializerSettings();

            camelCaseFormatter.ContractResolver = new CamelCasePropertyNamesContractResolver();

            Response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader, camelCaseFormatter));
            Response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
예제 #3
0
        // extension method to add pagination
        public static void AddPagination(this HttpResponse response,
                                         int currentPage, int itemsPerPage, int totalItems, int totalPages)
        {
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            //we need to send camelCase instead of TitleCase
            var camelCaseFormatter = new JsonSerializerSettings();

            camelCaseFormatter.ContractResolver = new CamelCasePropertyNamesContractResolver();
            // Add header, SerializeObject will covert the object to JSON formatted object
            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader, camelCaseFormatter));
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
예제 #4
0
        public static void AddPagination(this HttpResponse response, int currentPage, int itemsPerPage, int totalItems, int totalPages)
        {
            // ... OR anonymous object ...
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            //... format names of the HTTP parameters in HERADER to CAMELCASE
            var camelCaseFormater = new JsonSerializerSettings();

            camelCaseFormater.ContractResolver = new CamelCasePropertyNamesContractResolver();

            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader, camelCaseFormater));
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
예제 #5
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 camelCaseFormatting = new JsonSerializerSettings();

            camelCaseFormatting.ContractResolver = new CamelCasePropertyNamesContractResolver();
            //with second parameter force PascalCase to be camelCase
            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader, camelCaseFormatting));

            // make Pagination custom header available in browsers
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
        public static void AddPagination(this HttpResponse response, int currentPage, int itemsPerPage, int totalItems, int totalPages)
        {
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            // Angular app is dealing everything with camelCase therefore it is needed to be formatted that way
            var camelCaseFormatter = new JsonSerializerSettings();

            camelCaseFormatter.ContractResolver = new CamelCasePropertyNamesContractResolver();

            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader, camelCaseFormatter));

            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
예제 #7
0
        public static void AddPagination(this HttpResponse response, int currentPage,
                                         int itemsPerPage, int totalItems, int totalPages)
        {
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);
            // to send the headers as camel case
            var camelCaseFormatter = new JsonSerializerSettings();

            camelCaseFormatter.ContractResolver = new CamelCasePropertyNamesContractResolver();

            // https://www.newtonsoft.com/json/help/html/SerializeObject.htm - basically converts the pagination info into JSON format
            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader, camelCaseFormatter));
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
예제 #8
0
        public static void AddPagination(this HttpResponse response,
                                         int currentPage, int itemsPerPage, int totalItems, int totalPages)
        // Will add a paginationHeader class to the headers of the response returned
        {
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);
            // The vars returned in the pagination header need to be camel case because that's what angular uses
            var camelCaseFormatter = new JsonSerializerSettings();

            camelCaseFormatter.ContractResolver = new CamelCasePropertyNamesContractResolver();
            // Convert our paginationHeader to string values
            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader, camelCaseFormatter));
            // Expose the pagination header to cors errors associated with this
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
예제 #9
0
        public static void AddPaginationHeader(this HttpResponse response, int currentPage, int totalPages, int pageSize, int totalCount)
        {
            PaginationHeader        header           = new PaginationHeader(currentPage, totalPages, pageSize, totalCount);
            DefaultContractResolver contractResolver = new DefaultContractResolver
            {
                NamingStrategy = new CamelCaseNamingStrategy()
            };

            response.Headers.Add("Pagination", JsonConvert.SerializeObject(header, new JsonSerializerSettings
            {
                ContractResolver = contractResolver
            }));
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
예제 #10
0
        public static void AddPagination
        (
            this HttpResponse response,
            int currentPage,
            int itemsPerPage,
            int totalItems,
            int totalPages
        )
        {
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader));
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
예제 #11
0
        public static void Pagination(this HttpResponse response, int currentPage,
                                      int itemsPerPage, int totalItems, int totalPages)
        {
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            /* below two lines of code is used to format the header as camelCase,
             * in order for angular to utilize it; as angular wwon't utilize the default formatter
             * i.e. PascalCase */
            var formatter = new JsonSerializerSettings();

            formatter.ContractResolver = new CamelCasePropertyNamesContractResolver();

            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader, formatter));
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination"); // this is added to do with CORS error
        }
예제 #12
0
        /// <summary>
        /// This extends our HttpResponse to support pagination
        /// </summary>
        /// <param name="response"></param>
        /// <param name="currentPage"></param>
        /// <param name="itemsPerPage"></param>
        /// <param name="totalItems"></param>
        /// <param name="totalPages"></param>
        public static void AddPagination(this HttpResponse response, int currentPage, int itemsPerPage, int totalItems, int totalPages)
        {
            // Set up our http header
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            // This are just options to send back our header parameters as camelCase and not as TitleCase
            var camelCaseFormatter = new JsonSerializerSettings();

            camelCaseFormatter.ContractResolver = new CamelCasePropertyNamesContractResolver();

            // add our pagination headers to the response and serialize it to json format
            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader, camelCaseFormatter));
            // Add access control expose headers to pagination header to stop cors errors
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
예제 #13
0
        public static void AddPagination(this HttpResponse response, int currentPage,
                                         int itemsPerPage, int totalItems, int totalPages)
        {
            // new instance of pagination header class
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            // we need to convert the object into series of string values along with changing the format to camelcase
            var camelCaseFormatter = new JsonSerializerSettings();

            camelCaseFormatter.ContractResolver = new CamelCasePropertyNamesContractResolver();
            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader, camelCaseFormatter));

            // Exposing the header to avoid CORS error
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
예제 #14
0
        public static void AddPagination(this HttpResponse response, int currentPage, int itemsPerPage, int totalItems, int totalPages)
        {
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            // The key for the header will be pagination & passing the string values
            // We need to convert our object to a series of string of values using JsonConverter
            // Passing the value in camel case
            var camelCaseFormatter = new JsonSerializerSettings();

            camelCaseFormatter.ContractResolver = new CamelCasePropertyNamesContractResolver();
            response.Headers.Add("pagination", JsonConvert.SerializeObject(paginationHeader, camelCaseFormatter));

            // we need to expose the headers so that we don`t take a CORS error
            response.Headers.Add("Access-Control-Expose-Headers", "pagination");
        }
예제 #15
0
        //sending information down to the client for the pagination
        public static void AddPagination(this HttpResponse response,
                                         int currentPage, int itemsPerPage, int totalItems, int totalPages)
        {
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            //serializeObject() converts it to camelCase
            var camelCaseformatter = new JsonSerializerSettings();

            camelCaseformatter.ContractResolver = new CamelCasePropertyNamesContractResolver();

            //convert 'paginationHeader' from objet to string using jsonConvert
            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader, camelCaseformatter));
            //expose the headers so that we dont get a cors error
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
            //request a specific page number and page size
        }
예제 #16
0
        // Extension method for HttpResponse to add pagination to responses
        public static void AddPagination(this HttpResponse response, int currentPage, int itemsPerPage, int totalItems, int totalPages)
        {
            // Initialize a new instance of pagination using the given data
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            // Json serialization settings to format serialized object into camelCase
            var camelCaseFormatter = new JsonSerializerSettings();

            camelCaseFormatter.ContractResolver = new CamelCasePropertyNamesContractResolver();

            // Add the pagination to the response headers by serializing the pagination (sets property names to camel case)
            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader, camelCaseFormatter));

            // Allow pagination in our response headers to avoid CORS error
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
예제 #17
0
        } // ova alertify mislam bese za poraki da prakjas messsages

        public static void AddPagination(this HttpResponse response,
                                         int currentPage, int itemsPerPage, int totalItems, int totalPages) // 141
        {
            // za camel case da gi napravam infrmacii te vo PaginationHeader
            var camelCaseFormater = new JsonSerializerSettings();

            camelCaseFormater.ContractResolver = new CamelCasePropertyNamesContractResolver();
            // dole kaj SerialieObject dodavam vo zagradite (paginationHeader, *camelCaseFormater*)
            // bez ova ke imas problem vo SPA pri vlecenje informaciive (itemsPerPage, totalPages.. itn)
            // do tuka e za camel


            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);       // ova KE go vratam u HEADER

            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader, camelCaseFormater)); // Informaciite za Pageing gi pustam u HEADEROT
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");                                  // za da nemam COUSE ERROR
        }
예제 #18
0
        public static void AddPagination(this HttpResponse response,
                                         int currentPage, int itemsPerPage, int totalItems, int totalPages)
        {
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            /*
             * NOTE : JsonSerializerSettings &  CamelCasePropertyNamesContractResolver
             * angular deal with camelcase format otherwise we get in the header:
             * Pagination →{"CurrentPage":1,"ItemsPerPage":3,"TotalItems":3,"TotalPages":4}
             * and we need : Pagination →{"currentPage":1,"itemsPerPage":3,"totalItems":3,"totalPages":4
             */
            var camelCaseFormatter = new JsonSerializerSettings();

            camelCaseFormatter.ContractResolver = new CamelCasePropertyNamesContractResolver();
            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader, camelCaseFormatter));
            //we need also expose the Pagination header (like the errors in AddApplicationError)
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
예제 #19
0
        public static void AddPagination(this HttpResponse response, int currentPage,
                                         int itemsPerPage, int totalItems, int totalPages)
        {
            // create new PaginationHeader
            // this is the information we need to
            // pass back to the client so that it can handle
            // the paging on its side
            var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);

            // user camel case for json format
            var camelCaseFormatter = new JsonSerializerSettings();

            camelCaseFormatter.ContractResolver = new CamelCasePropertyNamesContractResolver();

            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader,
                                                                           camelCaseFormatter));
            // give client access to this header
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
예제 #20
0
        public static void AddPagination(this HttpResponse response,
                                         int currentPage,
                                         int itemsPerPage,
                                         int totalItems,
                                         int totalPages)
        {
            var paginationHeader = new PaginationHeader(currentPage,
                                                        itemsPerPage,
                                                        totalItems,
                                                        totalPages);

            response.Headers.Add("Pagination", JsonSerializer.Serialize(
                                     paginationHeader,
                                     new JsonSerializerOptions {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            }));

            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
        public static void AddPagination(this HttpResponse response, int currentPage,
                                         int itemsPerPage, int totalItems, int totalPages)
        {
            // This deals with what we are sending 'back' to the client

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

            // This will return in the header in the TitleCase something like
            // Pagination →{"CurrentPage":1,"ItemsPerPage":10,"TotalItems":14,"TotalPages":2}
            // But, since we will be consuming these headers on Angular, then we
            // will change the formatting into camelCase
            var camelCaseFormatter = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            response.Headers.Add("Pagination", JsonConvert.SerializeObject(paginationHeader,
                                                                           camelCaseFormatter));

            // We need to add Access-Control-Expose-Headers so that we will not get
            // a CORS error
            response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
        }
예제 #22
0
 public static void AddPagination(this HttpResponse response, PaginationHeader pagination)
 {
     response.Headers.Add("Pagination", JsonConvert.SerializeObject(pagination));
     response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
 }