コード例 #1
0
 public ActionResult <List <PetType> > Get([FromQuery] FilterModel filter)
 {
     if (string.IsNullOrEmpty(filter.SearchTerm) && string.IsNullOrEmpty(filter.SearchValue))
     {
         try
         {
             return(Ok(_petTypeService.ListPetTypes()));
         }
         catch (Exception e)
         {
             return(NotFound(e.Message));
         }
     }
     else
     {
         if (string.IsNullOrEmpty(filter.SearchTerm) || string.IsNullOrEmpty(filter.SearchValue))
         {
             return(BadRequest("You need to enter both a SearchTerm and a SearchValue"));
         }
         else
         {
             try
             {
                 return(Ok(_petTypeService.SearchForPetType(filter)));
             }
             catch (Exception e)
             {
                 return(NotFound(e.Message));
             }
         }
     }
 }