Permalink
Find file
654f371 Dec 3, 2016
33 lines (29 sloc) 1.21 KB
using Microsoft.AspNetCore.Http;
namespace Scheduler.API.Core
{
public static class Extensions
{
/// <summary>
/// Extension method to add pagination info to Response headers
/// </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);
response.Headers.Add("Pagination",
Newtonsoft.Json.JsonConvert.SerializeObject(paginationHeader));
// CORS
response.Headers.Add("access-control-expose-headers", "Pagination");
}
public static void AddApplicationError(this HttpResponse response, string message)
{
response.Headers.Add("Application-Error", message);
// CORS
response.Headers.Add("access-control-expose-headers", "Application-Error");
}
}
}