/// <summary> /// Gets animal from server /// </summary> /// <returns>int is -1 if server error, -2 if can't connect to server</returns> public static Tuple <Animal, int> getAnimal(int animalID) { string result = (RestService.GetCall(baseuri + "get_pets.php")); if (result.Equals("-2")) { return(Tuple.Create((Animal)null, -2)); } PetClass allPets = JsonConvert.DeserializeObject <PetClass>(result); foreach (Animal animal in allPets.pets) { if (animal.id == animalID) { return(Tuple.Create(animal, 1)); } } return(null); }
//public static Tuple<List<Animal>, int> getAnimalsByShelter(int shelterID) //{ // string result = (RestService.GetCall(baseuri + "get_pets.php?id=" + shelterID)); // PetClass allPets = JsonConvert.DeserializeObject<PetClass>(result); // List<Animal> ret = new List<Animal>(); // int temp; // if (int.TryParse(result, out temp)) // { // return Tuple.Create((List<Animal>)null, temp); // } // foreach (Animal animal in allPets.pets) // { // if (animal.shelter_id == shelterID) // { // ret.Add(animal); // } // } // return Tuple.Create(ret, 1); //} /// <summary> /// Gets all animals belonging to shelter with specific id /// </summary> /// <param name="shelterID"></param> /// <returns>int is -1 if server error, -2 if can't connect to server</returns> public static Tuple <List <Animal>, int> getAllAnimals(int shelterID) { string result = (RestService.GetCall(baseuri + "get_pets.php")); PetClass allPets = JsonConvert.DeserializeObject <PetClass>(result); List <Animal> ret = new List <Animal>(); int temp; if (int.TryParse(result, out temp)) { return(Tuple.Create((List <Animal>)null, temp)); } foreach (Animal animal in allPets.pets) { if (animal.shelter_id == shelterID) { ret.Add(animal); } } return(Tuple.Create(ret, 1)); }