Ejemplo n.º 1
0
        public ActionResult <IEnumerable <PetType> > Get([FromQuery] Filter filter)
        {
            List <PetType> types = new List <PetType>();

            try
            {
                if (string.IsNullOrEmpty(filter.Direction) || string.IsNullOrEmpty(filter.Field) || string.IsNullOrEmpty(filter.Term))
                {
                    types = _petTypesService.GetAllPetTypes();
                }
                else
                {
                    types = _petTypesService.GetAllPetTypes(filter);
                }
            }
            catch (InvalidDataException e)
            {
                return(StatusCode(500, e.Message));
            }
            catch (Exception)
            {
                return(StatusCode(500, ExceptionMessageConstants.NonSpecificUIMessage));
            }

            if (types.Count == 0)
            {
                return(StatusCode(404, "Did not find any entries"));
            }
            else
            {
                return(Ok(types));
            }
        }
Ejemplo n.º 2
0
 public ActionResult <List <PetType> > Get()
 {
     try
     {
         return(_petTypeService.GetAllPetTypes());
     }
     catch (Exception e)
     {
         return(StatusCode(500, "Task failed successfully"));
     }
 }
        public ActionResult <List <PetType> > Get([FromQuery] string prop, string val)//Filter filter)
        {
            if (prop != null)
            {
                if (val == null)
                {
                    return(StatusCode(500, "Request Failed - no value provided for search"));
                }
                Filter filter   = new Filter();
                string property = prop.ToLower();
                string value    = val.ToLower();
                filter.Property = property;
                filter.Value    = value;

                if (property == "name")
                {
                    List <PetType> searchedPetTypes = _petTypeService.FindPetTypesByProperty(filter);
                    if (searchedPetTypes.Count == 0)
                    {
                        return(StatusCode(404, "No pet type with the " + filter.Property + " '" + filter.Value + "' was  found"));
                    }
                    else
                    {
                        return(StatusCode(200, searchedPetTypes));
                    }
                }
                else
                {
                    return(StatusCode(500, "Request Failed - The pet type property '" + property + "' does not exist"));
                }
            }
            else
            {
                return(StatusCode(200, _petTypeService.GetAllPetTypes()));
            }
        }
Ejemplo n.º 4
0
        public ActionResult <IEnumerable <PetType> > Get()
        {
            try
            {
                var petTypes = _petTypeService.GetAllPetTypes();
                if (petTypes.Count < 1)
                {
                    return(StatusCode(404, "no pet types to show"));
                }

                return(petTypes);
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
Ejemplo n.º 5
0
 // Metode za dohvaćanje podataka o tipovima ljubimca
 // Naziv tipa prema ID-ju
 public string GetTypeDesc(int typeId)
 {
     return(_petTypeService.GetAllPetTypes().Where(t => t.PetTypeId == typeId).Select(t => t.PetTypeDesc).FirstOrDefault());
 }
Ejemplo n.º 6
0
 public IEnumerable <PetType> PopulateGrid(int page = 1)
 {
     return(_petTypeService.GetAllPetTypes().Skip((page - 1) * PageSize).Take(PageSize).ToArray());
 }