internal static Pet UpdateSpeciesOfPet(Pet updatedPet, Pet.Species updateValue) { List <Pet> foundPets = (allThePets.Where(pet => pet == updatedPet)).ToList(); if (foundPets.Count <= 0 || foundPets.Count > 1) { throw new InvalidDataException(message: "I am sorry wrong amonut of pets found"); } else { foundPets[0].PetSpecies = updateValue; return(foundPets[0]); } }
public List <Pet> SearchForPet(int toSearchInt, string searchValue) { switch (toSearchInt) { case 1: return(_petRepo.FindPetsByName(searchValue).ToList()); case 2: return(_petRepo.FindPetsByColor(searchValue).ToList()); case 3: int theSearch; Pet.Species theSearchCriteria = Pet.Species.Dog; if (int.TryParse(searchValue, out theSearch) && theSearch >= 1 && theSearch <= 7) { switch (theSearch) { case 1: theSearchCriteria = Pet.Species.Dog; break; case 2: theSearchCriteria = Pet.Species.Cat; break; case 3: theSearchCriteria = Pet.Species.Fish; break; case 4: theSearchCriteria = Pet.Species.Horse; break; case 5: theSearchCriteria = Pet.Species.Hamster; break; case 6: theSearchCriteria = Pet.Species.Gerbil; break; case 7: theSearchCriteria = Pet.Species.Rabbit; break; default: throw new InvalidDataException(message: "Index for species is out of bounds"); } } return(_petRepo.FindPetsBySpecies(theSearchCriteria).ToList()); case 4: DateTime theDateValue = DateTime.Now; if (DateTime.TryParse(searchValue, out theDateValue)) { return(_petRepo.SearchPetsByBirthYear(theDateValue).ToList()); } else { throw new InvalidDataException(message: "You have not entered a valid date."); } case 5: DateTime theSoldValue = DateTime.Now; if (DateTime.TryParse(searchValue, out theSoldValue)) { return(_petRepo.FindPetsBySoldDate(theSoldValue).ToList()); } else { throw new InvalidDataException(message: "You have not entered a valid date."); } case 6: return(_petRepo.FindPetsByPreviousOwner(searchValue).ToList()); case 7: long thePriceValue = 0; if (long.TryParse(searchValue, out thePriceValue)) { return(_petRepo.FindPetsByPrice(thePriceValue).ToList()); } else { throw new InvalidDataException(message: "You have not entered a valid price."); } case 9: int searchId; if (int.TryParse(searchValue, out searchId)) { return(new List <Pet> { _petRepo.FindPetByID(searchId) }); } else { throw new InvalidDataException(message: "You have not given me a Nr to search the Id's for."); } default: throw new InvalidDataException(message: "Something unexpected went wrong."); } }
public Pet UpdatePet(Pet updatedPet, int toUpdateInt, string updateValue) { switch (toUpdateInt) { case 1: return(_petRepo.UpdateNameOfPet(updatedPet, updateValue)); case 2: return(_petRepo.UpdateColorOfPet(updatedPet, updateValue)); case 3: int theUpdate; Pet.Species theupdatedValue = Pet.Species.Dog; if (int.TryParse(updateValue, out theUpdate) && theUpdate >= 1 && theUpdate <= 7) { switch (theUpdate) { case 1: theupdatedValue = Pet.Species.Dog; break; case 2: theupdatedValue = Pet.Species.Cat; break; case 3: theupdatedValue = Pet.Species.Fish; break; case 4: theupdatedValue = Pet.Species.Horse; break; case 5: theupdatedValue = Pet.Species.Hamster; break; case 6: theupdatedValue = Pet.Species.Gerbil; break; case 7: theupdatedValue = Pet.Species.Rabbit; break; default: throw new InvalidDataException(message: "Index for species is out of bounds"); } } return(_petRepo.UpdateSpeciesOfPet(updatedPet, theupdatedValue)); case 4: DateTime theUpdateValue = DateTime.Now; if (DateTime.TryParse(updateValue, out theUpdateValue)) { return(_petRepo.UpdateBirthdayOfPet(updatedPet, theUpdateValue)); } else { throw new InvalidDataException(message: "You have not entered a valid date."); } case 5: DateTime theSoldUpdateValue = DateTime.Now; if (DateTime.TryParse(updateValue, out theSoldUpdateValue)) { return(_petRepo.UpdateSoldDateOfPet(updatedPet, theSoldUpdateValue)); } else { throw new InvalidDataException(message: "You have not entered a valid date."); } case 6: return(_petRepo.UpdatePreviousOwnerOfPet(updatedPet, updateValue)); case 7: long thePriceValue = 0; if (long.TryParse(updateValue, out thePriceValue)) { return(_petRepo.UpdatePriceOfPet(updatedPet, thePriceValue)); } else { throw new InvalidDataException(message: "You have not entered a valid price."); } case 8: int id; if (int.TryParse(updateValue, out id)) { return(_petRepo.UpdateOwnerOfPet(updatedPet, id)); } else { throw new InvalidDataException(message: "You have not entered a valid id."); } default: throw new InvalidDataException(message: "Something unexpected went wrong."); } }
public IEnumerable <Pet> FindPetsBySpecies(Pet.Species theSearchCriteria) { IEnumerable <Pet> petsBySpecies = PetDB.allThePets.Where(pet => pet.PetSpecies == theSearchCriteria); return(petsBySpecies); }
public Pet UpdateSpeciesOfPet(Pet updatedPet, Pet.Species updateValue) { return(PetDB.UpdateSpeciesOfPet(updatedPet, updateValue)); }