Exemple #1
0
        public IActionResult Get([FromQuery] LinkRequest request)
        {
            int    requestedPage     = request.Page ?? 1;
            int    requestedPageSize = request.PageSize ?? 10;
            string search            = request.Search ?? "";

            IEnumerable <Link> links = _repository.GetLinks(search, requestedPage, requestedPageSize);

            int linksCountMatchedSearch = _repository.LinksCount(search);
            int maxPage = (linksCountMatchedSearch / requestedPageSize);

            maxPage += linksCountMatchedSearch % requestedPageSize == 0 ? 0 : 1;

            IEnumerable <LinkGetResult.SendedLinkToClient> linkInformations = links.Select(x => new LinkGetResult.SendedLinkToClient(x));
            LinkGetResult result = new LinkGetResult(linkInformations, new LinkGetResult.PageInfo(requestedPage, maxPage));

            return(Ok(result));
        }