public ActionResult <IEnumerable <Pet> > Get([FromQuery] PageFilter pageFilter)
 {
     try
     {
         if (pageFilter.CurrentPage < 0 || pageFilter.ItemsPerPage < 0)
         {
             throw new InvalidDataException("CurrentPage and ItemsPerPage have to be higher than 0");
         }
         if ((pageFilter.CurrentPage - 1 * pageFilter.ItemsPerPage) >= _petService.Count())
         {
             throw new InvalidDataException("Index out of bounds");
         }
         if (_petService.GetFilteredPets(pageFilter) != null)
         {
             return(Ok(_petService.GetFilteredPets(pageFilter)));
         }
         //if (_petService.GetAllPets() != null)
         //{
         //    return Ok(_petService.GetAllPets());
         //}
         return(NotFound());
     }
     catch (System.Exception)
     {
         return(StatusCode(500, "Error when looking for list of pets"));
     }
 }
Exemple #2
0
 public ActionResult <IEnumerable <Pet> > Get([FromQuery] Filter filter)
 {
     if (_petService.Count() == 0)
     {
         return(BadRequest("Pets list is empty."));
     }
     else
     {
         if (filter.CurrentPage < 0 || filter.ItemsPrPage < 0)
         {
             return(BadRequest("Current page and items per page has to be at least 0"));
         }
         if (_petService.Count() < filter.ItemsPrPage * (filter.CurrentPage - 1))
         {
             return(BadRequest($"Page number {filter.CurrentPage} is not available"));
         }
         //return _petService.GetPets();
         return(_petService.GetFilteredPets(filter));
     }
 }