Exemplo n.º 1
0
        /// <summary>
        /// Get roles from repository and auto map to Dto
        /// </summary>
        /// <typeparam name="T">Identifier or detail Dto</typeparam>
        /// <param name="baseResourceParameters">Standard parameters for representing resource</param>
        /// <returns></returns>
        private PagedCollection <T> GetRoles <T>(IdResourceParameters baseResourceParameters) where T : class
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = baseResourceParameters.PageNumber,
                PageSize   = baseResourceParameters.PageSize
            };

            var orderby = Extensions.GetOrderBy <IdentityRole <Guid> >(baseResourceParameters.OrderBy, "asc");

            var rolesFromManager = _roleManager.Roles.ToList();

            if (rolesFromManager != null)
            {
                // Map EF entity to Dto
                var mappedRoles = PagedCollection <T> .Create(_mapper.Map <PagedCollection <T> >(rolesFromManager),
                                                              pagingInfo.PageNumber,
                                                              pagingInfo.PageSize,
                                                              rolesFromManager.Count);

                // Prepare pagination data for response
                var paginationMetadata = new
                {
                    totalCount  = mappedRoles.TotalCount,
                    pageSize    = mappedRoles.PageSize,
                    currentPage = mappedRoles.CurrentPage,
                    totalPages  = mappedRoles.TotalPages,
                };

                Response.Headers.Add("X-Pagination",
                                     JsonConvert.SerializeObject(paginationMetadata));

                return(mappedRoles);
            }

            return(null);
        }