public IActionResult GetPosts([FromQuery] PostQueryFilter filters) { //var posts = new PostRepository().GetPosts();} var posts = postServices.GetPosts(filters); //var postDto = _mapper.Map<PostDto>(posts); //AutoMapper var postsDto = _mapper.Map <IEnumerable <PostDto> >(posts); var metadata = new Metadata { TotalPage = posts.TotalPages, PageSize = posts.PageSize, TotalCount = posts.TotalCount, CurrentPage = posts.CurrentPage, HasNextPage = posts.HasNextPage, HasPreviuosPage = posts.HasPreviousPage, //NexPageUrl = _uriService.GetPostPaginationUri(filters,"/api/Post").ToString() NexPageUrl = _uriService.GetPostPaginationUri(filters, Url.RouteUrl(nameof(GetPosts))).ToString(), PreviuosPageUrl = _uriService.GetPostPaginationUri(filters, Url.RouteUrl(nameof(GetPosts))).ToString() }; var response = new ApiResponse <IEnumerable <PostDto> >(postsDto) { Meta = metadata }; ////Implementar Paginacion ojo ** se dejo igual porque el PagedList hereda de un list //var postsDto = _mapper.Map<PagedList<PostDto>>(posts); //var response = new ApiResponse<PagedList<PostDto>>(postsDto); //------------------------------------------------------------------------------------- //var postsDto = posts.Select(x => new PostDto //{ // Postid = x.Postid, // Date = x.Date, // Image = x.Image, // UserId = x.UserId //}); //var metadata = new //{ // posts.TotalPages, // posts.PageSize, // posts.TotalCount, // posts.CurrentPage, // posts.HasNextPage, // posts.HasPreviousPage //}; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); ///primera opcion de paginacion return(Ok(response)); }
public async Task <IActionResult> Get(string languageCode = LanguageCode.English) { var user = await _userManager.GetUserAsync(User); var posts = _postServices.GetPosts(languageCode); return(Ok(posts)); }
public async Task <IActionResult> Index() { List <Post> posts = await postServices.GetPosts(); return(View(posts)); }