public ActionResult <FilteredList <ProductModel> > Get([FromQuery] ProductModelFilter filter)
 {
     try
     {
         FilteredList <ProductModel> filteredProductModels = _productModelService.ReadAll(filter);
         return(Ok(new FilteredList <object> {
             TotalPages = filteredProductModels.TotalPages, Data = filteredProductModels.Data
         }));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
        public FilteredList <ProductModel> ReadAll(ProductModelFilter filter)
        {
            FilteredList <ProductModel> filteredList = new FilteredList <ProductModel>();

            if (filter.CurrentPage == 0 && filter.ItemsPerPage == 0)
            {
                filteredList.Data = _ctx.ProductModels.AsNoTracking();
                return(filteredList);
            }
            else
            {
                if (filter.CategoryType == CategoryType.Default)
                {
                    filteredList.Data = _ctx.ProductModels.AsNoTracking()
                                        .Skip((filter.CurrentPage - 1) * filter.ItemsPerPage).Take(filter.ItemsPerPage);

                    if (_ctx.ProductModels.Count() % filter.ItemsPerPage != 0)
                    {
                        filteredList.TotalPages = (_ctx.ProductModels.Count() / filter.ItemsPerPage) + 1;
                    }
                    else
                    {
                        filteredList.TotalPages = _ctx.ProductModels.Count() / filter.ItemsPerPage;
                    }
                }
                else
                {
                    filteredList.Data = _ctx.ProductModels.AsNoTracking().Where(pm => pm.ProductCategory.Name.Equals(filter.CategoryType.ToString()))
                                        .Skip((filter.CurrentPage - 1) * filter.ItemsPerPage).Take(filter.ItemsPerPage);

                    int totalFilteredProductModels = _ctx.ProductModels.Where(pm => pm.ProductCategory.Name.Equals(filter.CategoryType.ToString())).Count();
                    if (totalFilteredProductModels % filter.ItemsPerPage != 0)
                    {
                        filteredList.TotalPages = (totalFilteredProductModels / filter.ItemsPerPage) + 1;
                    }
                    else
                    {
                        filteredList.TotalPages = totalFilteredProductModels / filter.ItemsPerPage;
                    }
                }
            }

            return(filteredList);
        }
 public FilteredList <ProductModel> ReadAll(ProductModelFilter filter)
 {
     return(_productModelRepository.ReadAll(filter));
 }