public IActionResult AllGalleryPagination([FromBody] SearchAllPictureInputModel model,
                                                  int itemsPerPage = 1, int currentPage = 1)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var response = service.SearchAllPictures(model, itemsPerPage, currentPage);

            return(Ok(response));
        }
        public List <SearchPictureOutputModel> SearchAllPictures(SearchAllPictureInputModel input)
        {
            var res = new List <SearchPictureOutputModel>();

            using (IDbConnection db = new SqlConnection(Global.Connection))
            {
                res = db.Query <SearchPictureOutputModel>("sp_SearchPicture", input,
                                                          commandType: CommandType.StoredProcedure).ToList();
            }
            return(res);
        }
Ejemplo n.º 3
0
        public GalleryViewModel SearchAllPictures(SearchAllPictureInputModel model, int itemsPerPage, int currentPage)
        {
            var images = repo.SearchAllPictures(model);

            Each(images, i => ConvertCategoriesToArr(i));

            var totalItems = images.Count();

            images = images
                     .Skip((currentPage - 1) * itemsPerPage)
                     .Take(itemsPerPage)
                     .OrderBy(i => i.CreatedAt)
                     .ToList();

            var response = new GalleryViewModel
            {
                Images     = images,
                TotalItems = totalItems
            };

            return(response);
        }