Ejemplo n.º 1
0
 public ActionResult <IEnumerable <PetColor> > Get([FromQuery] FilterModel filter)
 {
     if (string.IsNullOrEmpty(filter.SearchTerm) && string.IsNullOrEmpty(filter.SearchValue))
     {
         if (filter.CurrentPage == 0 && filter.ItemsOnPage == 0)
         {
             if (string.IsNullOrEmpty(filter.OrganizeOrder))
             {
                 try
                 {
                     return(Ok(_petColorService.GetAllPetColors()));
                 }
                 catch (Exception e)
                 {
                     return(NotFound(e.Message));
                 }
             }
             else if (filter.OrganizeOrder.ToLower().Equals("asc") || filter.OrganizeOrder.ToLower().Equals("desc"))
             {
                 try
                 {
                     return(Ok(_petColorService.GetFilteredPetColors(filter)));
                 }
                 catch (Exception e)
                 {
                     return(NotFound(e.Message));
                 }
             }
             else
             {
                 return(BadRequest("You need to enter OrganizeOrder asc or desc"));
             }
         }
         else
         {
             try
             {
                 return(Ok(_petColorService.GetFilteredPetColors(filter)));
             }
             catch (Exception e)
             {
                 return(NotFound(e.Message));
             }
         }
     }
     else
     {
         if (string.IsNullOrEmpty(filter.SearchTerm) || string.IsNullOrEmpty(filter.SearchValue))
         {
             return(BadRequest("Enter SearchTerm and SearchValue, NOT THAT HARD!"));
         }
         else
         {
             try
             {
                 List <PetColor> foundColors = _petColorService.SearchForPetColor(filter);
                 if (foundColors.Count < 1)
                 {
                     return(NotFound("No pets with thise colors exist. You probably did something wrong with your life"));
                 }
                 else
                 {
                     return(Ok(foundColors));
                 }
             }
             catch (Exception e)
             {
                 return(NotFound(e.Message));
             }
         }
     }
 }
Ejemplo n.º 2
0
 public ActionResult <IEnumerable <PetColor> > Get([FromQuery] FilterModel filter)
 {
     if (string.IsNullOrEmpty(filter.SearchTerm) && string.IsNullOrEmpty(filter.SearchValue))
     {
         if (filter.CurrentPage == 0 && filter.ItemsPrPage == 0)
         {
             if (string.IsNullOrEmpty(filter.SortOrder))
             {
                 try
                 {
                     return(Ok(_petColorService.GetAllPetColors()));
                 }
                 catch (Exception e)
                 {
                     return(NotFound(e.Message));
                 }
             }
             else if (filter.SortOrder.ToLower().Equals("asc") || filter.SortOrder.ToLower().Equals("desc"))
             {
                 try
                 {
                     return(Ok(_petColorService.GetAllFilteredPetColors(filter)));
                 }
                 catch (Exception e)
                 {
                     return(NotFound(e.Message));
                 }
             }
             else
             {
                 return(BadRequest("You need to enter SortOrder 'asc' or 'desc'"));
             }
         }
         else
         {
             try
             {
                 return(Ok(_petColorService.GetAllFilteredPetColors(filter)));
             }
             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
             {
                 List <PetColor> allColorsFound = _petColorService.SearchPetColor(filter);
                 if (allColorsFound.Count < 1)
                 {
                     return(NotFound("No pets with those parameters could be found."));
                 }
                 else
                 {
                     return(Ok(allColorsFound));
                 }
             }
             catch (Exception e)
             {
                 return(NotFound(e.Message));
             }
         }
     }
 }