private void RemoveAnimal() { var animals = Query.SearchForAnimalByMultipleTraits(UserInterface.GetAnimalCriteria(), "Employee").ToList(); if (animals.Count > 1) { UserInterface.DisplayUserOptions("Several animals found please refine your search."); UserInterface.DisplayAnimals(animals); UserInterface.DisplayUserOptions("Press enter to continue"); Console.ReadLine(); return; } else if (animals.Count < 1) { UserInterface.DisplayUserOptions("Animal not found please use different search criteria"); return; } var animal = animals[0]; List <string> options = new List <string>() { "Animal found:", animal.Name, animal.Category.Name, "would you like to delete?" }; if ((bool)UserInterface.GetBitData(options)) { Query.RemoveAnimal(animal); } }
private void RemoveAnimal() { Dictionary <int, string> searchDictionary = UserInterface.GetAnimalCriteria(); var animals = Query.SearchForAnimalByMultipleTraits(searchDictionary).ToList(); while (animals.Count > 1) { UserInterface.DisplayUserOptions("Several animals found please refine your search."); UserInterface.DisplayAnimals(animals); UserInterface.DisplayUserOptions("Press enter to continue searching"); Console.ReadLine(); searchDictionary = UserInterface.GetAnimalCriteria(); animals = Query.SearchForAnimalByMultipleTraits(searchDictionary).ToList(); } if (animals.Count < 1) { UserInterface.DisplayUserOptions("Animal not found please use different search criteria"); return; } var animal = animals[0]; List <string> options = new List <string>() { "Animal found:", animal.Name, animal.Category.Name, "would you like to delete?" }; if ((bool)UserInterface.GetBitData(options)) { Query.RemoveAnimal(animal); } else { UserInterface.DisplayUserOptions("Animal was not deleted. Press any key to continue."); Console.ReadLine(); } }
internal static List <Animal> SearchForAnimalByMulitpleTraits() { HumaneSocietyDataContext db = new HumaneSocietyDataContext(); Dictionary <int, string> searchCriteria; searchCriteria = UserInterface.GetAnimalCriteria(); //List<Animal> animalsFound = db.Animals.ToList(); List <Animal> animalsFound = db.Animals.Where(a => a.AdoptionStatus == null || a.AdoptionStatus == "denied").ToList(); foreach (var keyValuePair in searchCriteria) { // searchCriteria [0]: {[1, Dog]} [1]: {[9, True]} switch (keyValuePair.Key) { // "1. Category", "2. Name", "3. Age", "4. Demeanor", "5. Kid friendly", "6. Pet friendly", "7. Weight", "8. ID", "9. Gender" case 1: // lookup Dog's CategoryID var categoryID = db.Categories.Where(c => c.Name == keyValuePair.Value).Select(c => c.CategoryId).First(); animalsFound = animalsFound.Where(a => a.CategoryId == categoryID).ToList(); break; case 2: // Name animalsFound = animalsFound.Where(a => a.Name == keyValuePair.Value).ToList(); break; case 3: // Age animalsFound = animalsFound.Where(a => a.Name == keyValuePair.Value).ToList(); break; case 4: // Demeanor animalsFound = animalsFound.Where(a => a.Demeanor == keyValuePair.Value).ToList(); break; case 5: // Kid friendly animalsFound = animalsFound.Where(a => a.KidFriendly == Convert.ToBoolean(keyValuePair.Value)).ToList(); break; case 6: // Pet friendly animalsFound = animalsFound.Where(a => a.PetFriendly == Convert.ToBoolean(keyValuePair.Value)).ToList(); break; case 7: // Weight animalsFound = animalsFound.Where(a => a.Weight == Convert.ToInt32(keyValuePair.Value)).ToList(); break; case 8: // ID animalsFound = animalsFound.Where(a => a.AnimalId == Convert.ToInt32(keyValuePair.Value)).ToList(); break; case 9: // Gender animalsFound = animalsFound.Where(a => a.Gender == keyValuePair.Value).ToList(); break; } } return(animalsFound); }
protected IQueryable <Animal> SearchForAnimal() { HumaneSocietyDataContext context = new HumaneSocietyDataContext(); var animals = from data in context.Animals select data; var searchParameters = UserInterface.GetAnimalCriteria(); if (searchParameters.ContainsKey(1)) { animals = (from animal in animals where animal.Species.Name == searchParameters[1] select animal); } if (searchParameters.ContainsKey(2)) { animals = (from animal in animals where animal.Name == searchParameters[2] select animal); } if (searchParameters.ContainsKey(3)) { animals = (from animal in animals where animal.Age == int.Parse(searchParameters[3]) select animal); } if (searchParameters.ContainsKey(4)) { animals = (from animal in animals where animal.Demeanor == searchParameters[4] select animal); } if (searchParameters.ContainsKey(5)) { bool parameter = GetBoolParamater(searchParameters[5]); animals = (from animal in animals where animal.KidFriendly == parameter select animal); } if (searchParameters.ContainsKey(6)) { bool parameter = GetBoolParamater(searchParameters[6]); animals = (from animal in animals where animal.PetFriendly == parameter select animal); } if (searchParameters.ContainsKey(7)) { animals = (from animal in animals where animal.Weight == int.Parse(searchParameters[7]) select animal); } if (searchParameters.ContainsKey(8)) { animals = (from animal in animals where animal.AnimalId == int.Parse(searchParameters[8]) select animal); } return(animals); }
private void CheckAnimalStatus() { Console.Clear(); var animals = Query.SearchForAnimalByMultipleTraits(UserInterface.GetAnimalCriteria(), "Employee").ToList(); if (animals.Count > 1) { UserInterface.DisplayUserOptions("Several animals found"); UserInterface.DisplayAnimals(animals); UserInterface.DisplayUserOptions("Enter the ID of the animal you would like to check"); int ID = UserInterface.GetIntegerData(); CheckAnimalStatus(ID); return; } if (animals.Count == 0) { UserInterface.DisplayUserOptions("Animal not found please use different search criteria"); return; } RunCheckMenu(animals[0]); }
private void RunSearch() { Console.Clear(); var animals = Query.SearchForAnimalByMultipleTraits(UserInterface.GetAnimalCriteria()).ToList(); if (animals.Count > 1) { UserInterface.DisplayUserOptions("Several animals found"); UserInterface.DisplayAnimals(animals); } else if (animals.Count == 0) { UserInterface.DisplayUserOptions("No animals found please try another search"); } else { UserInterface.DisplayAnimalInfo(animals[0]); } UserInterface.DisplayUserOptions("Press enter to continue"); Console.ReadLine(); }
internal static List <Animal> SearchForAnimalByMultipleTraits() { HumaneSocietyDataContext db = new HumaneSocietyDataContext(); Dictionary <int, string> keyValuePairs = UserInterface.GetAnimalCriteria(); List <Animal> foundAnimals = new List <Animal>(); foreach (KeyValuePair <int, string> entry in keyValuePairs) { switch (entry.Key) { case 1: var searchCategory = db.Categories.Where(c => c.Name == entry.Value); foreach (var animals in searchCategory) { var searchAnimal = db.Animals.Where(a => a.CategoryId == animals.CategoryId); foreach (var animal in searchAnimal) { foundAnimals.Add(animal); } } break; case 2: var searchAnimalName = db.Animals.Where(n => n.Name == entry.Value); foreach (var animal in searchAnimalName) { foundAnimals.Add(animal); } break; case 3: var searchAge = db.Animals.Where(a => a.Age == Convert.ToInt64(entry.Value)); foreach (var animal in searchAge) { foundAnimals.Add(animal); } break; case 4: var searchDemeanor = db.Animals.Where(d => d.Demeanor == entry.Value); foreach (var animal in searchDemeanor) { foundAnimals.Add(animal); } break; case 5: var searchKidFriendly = db.Animals.Where(k => k.KidFriendly == Convert.ToBoolean(entry.Value)); foreach (var animal in searchKidFriendly) { foundAnimals.Add(animal); } break; case 6: var searchPetFriendly = db.Animals.Where(k => k.PetFriendly == Convert.ToBoolean(entry.Value)); foreach (var animal in searchPetFriendly) { foundAnimals.Add(animal); } break; case 7: var searchWeight = db.Animals.Where(w => w.Weight == Convert.ToInt64(entry.Value)); foreach (var animal in searchWeight) { foundAnimals.Add(animal); } break; case 8: var searchAnimalId = db.Animals.Where(a => a.AnimalId == Convert.ToInt64(entry.Value)); foreach (var animal in searchAnimalId) { foundAnimals.Add(animal); } break; default: break; } } var catchthing = foundAnimals.Distinct(); return(catchthing.ToList());; }