Example #1
0
        protected Dictionary <int, string> GetAnimalCriteria()
        {
            Dictionary <int, string> searchParameters = new Dictionary <int, string>();
            bool isSearching = true;

            while (isSearching)
            {
                Console.Clear();
                List <string> options = new List <string>()
                {
                    "Select Search Criteia: (Enter number and choose finished when finished)", "1. Category", "2. Breed", "3. Name", "4. Age", "5. Demeanor", "6. Kid friendly", "7. Pet friendly", "8. Weight", "9. ID", "10. Finished"
                };
                UserInterface.DisplayUserOptions(options);
                string input = UserInterface.GetUserInput();
                if (input.ToLower() == "10" || input.ToLower() == "finished")
                {
                    isSearching = false;
                    continue;
                }
                else
                {
                    searchParameters = UserInterface.EnterSearchCriteria(searchParameters, input);
                }
            }
            return(searchParameters);
        }
Example #2
0
        public void UpdateAnimal(Animal animal, Dictionary <int, string> updates = null)
        {
            if (updates == null)
            {
                updates = new Dictionary <int, string>();
            }

            List <string> options = new List <string>()
            {
                "Select Update:", "1. Category", "2. Name", "3. Age", "4. Demeanor", "5. Kid friendly", "6. Pet friendly", "7. Weight", "8. Finished", "You will be prompted again for any additional updates."
            };

            UserInterface.DisplayUserOptions(options);
            string input = UserInterface.GetUserInput();

            if (input.ToLower() == "8" || input.ToLower() == "finished")
            {
                Query.UpdateAnimal(animal.AnimalId, updates);
            }
            else
            {
                updates = UserInterface.EnterSearchCriteria(updates, input);
                UpdateAnimal(animal, updates);
            }
        }
Example #3
0
        private void UpdateAnimal(Animal animal, Dictionary <int, string> updates = null)
        {
            if (updates == null)
            {
                updates = new Dictionary <int, string>();
            }
            List <string> options = new List <string>()
            {
                "Select Updates: (Enter number and choose finished when finished)", "1. Category", "2. Name", "3. Age", "4. Demeanor", "5. Kid friendly", "6. Pet friendly", "7. Weight", "8. Diet Plan", "9. Finished"
            };                                                                                                                                                                                                                                                     // Figure out today!

            UserInterface.DisplayUserOptions(options);
            string input = UserInterface.GetUserInput();

            if (input.ToLower() == "9" || input.ToLower() == "finished")
            {
                Query.EnterAnimalUpdate(animal, updates);
            }
            else
            {
                input   = input == "8" ? "9" : input;
                updates = UserInterface.EnterSearchCriteria(updates, input);
                UpdateAnimal(animal);
            }
        }
        internal static void UpdateAnimal(int animalId, Dictionary <int, string> updates)
        {
            var animalOnDB = db.Animals.Where(a => a.AnimalId == animalId).SingleOrDefault();

            foreach (var items in updates) //query through database using animalId.  for each over a dictionary witha switch case (animal.key = animal.value) switch over key in dictionary

            {
                switch (items.Key)
                {
                case 1:
                    var cata = db.Categories.Where(c => c.Name == items.Value).SingleOrDefault();
                    animalOnDB.CategoryId = cata.CategoryId;
                    break;

                case 2:
                    animalOnDB.Name = items.Value;
                    break;

                case 3:
                    var age = db.Animals.Where(a => a.Name == items.Value).SingleOrDefault();
                    animalOnDB.Age = age.Age;
                    break;

                case 4:
                    animalOnDB.Demeanor = items.Value;
                    break;

                case 5:
                    var kids = db.Animals.Where(k => k.Name == items.Value).SingleOrDefault();
                    animalOnDB.KidFriendly = kids.KidFriendly;
                    break;

                case 6:
                    var pets = db.Animals.Where(p => p.Name == items.Value).SingleOrDefault();
                    animalOnDB.PetFriendly = pets.PetFriendly;
                    break;

                case 7:
                    var wt = db.Animals.Where(w => w.Name == items.Value).SingleOrDefault();
                    animalOnDB.Weight = wt.Weight;
                    break;
                }
                string input = UserInterface.GetUserInput();
                if (input.ToLower() == "8" || input.ToLower() == "finished")
                {
                    Query.UpdateAnimal(animalId, updates);
                }
                else
                {
                    updates = UserInterface.EnterSearchCriteria(updates, input);
                    UpdateAnimal(animalId, updates);
                }
            }
        }
        private void UpdateAnimal(Animal animal)
        {
            Dictionary <int, string> updates = new Dictionary <int, string>();
            List <string>            options = new List <string>()
            {
                "Select Updates: (Enter number and choose finished when finished)", "1. Category", "2. Breed", "3. Name", "4. Age", "5. Demeanor", "6. Kid friendly", "7. Pet friendly", "8. Weight", "9. Finished"
            };

            UserInterface.DisplayUserOptions(options);
            string input = UserInterface.GetUserInput();

            if (input.ToLower() == "9" || input.ToLower() == "finished")
            {
                Query.EnterUpdate(animal, updates);
            }
            else
            {
                updates = UserInterface.EnterSearchCriteria(updates, input);
            }
        }
Example #6
0
        private void UpdateAnimal(Animal animal)
        {
            Dictionary <int, string> updates = new Dictionary <int, string>();
            List <string>            options = new List <string>()
            {
                "Select Updates: (Enter number and choose finished when finished)", "1. Species", "2. Name", "3. Age", "4. Demeanor", "5. Kid friendly", "6. Pet friendly", "7. Weight", "8. ID", "9.Finished"
            };
            bool isFinishedUpdating = false;

            while (!isFinishedUpdating)
            {
                UserInterface.DisplayUserOptions(options);
                string input = UserInterface.GetUserInput();
                if (input.ToLower() == "9" || input.ToLower() == "finished")
                {
                    Query.EnterUpdate(animal, updates);
                    isFinishedUpdating = true;
                }
                else
                {
                    updates = UserInterface.EnterSearchCriteria(updates, input);
                }
            }
        }
        private void UpdateAnimal(Animal animal, Dictionary <int, string> updates = null)
        {
            if (updates == null)
            {
                updates = new Dictionary <int, string>();
            }
            List <string> options = new List <string>()
            {
                "Select Updates: (Enter number and choose finished when finished)", "1. Name", "2. Weight", "3. Age", "4. Demeanor", "5. Kid friendly", "6. Pet friendly", "7. Gender", "8. Adoption Status", "9. Room", "10. finished"
            };

            UserInterface.DisplayUserOptions(options);
            string input = UserInterface.GetUserInput();

            if (input.ToLower() == "10" || input.ToLower() == "finished")
            {
                Query.EnterAnimalUpdate(animal, updates);
            }
            else
            {
                updates = UserInterface.EnterSearchCriteria(updates, input, animal);
                UpdateAnimal(animal, updates);
            }
        }
Example #8
0
        public static void EnterUpdate(Animal animal, Dictionary <int, string> updates)
        {
            HumaneSocietyDataContext db = new HumaneSocietyDataContext();
            var updatedAnimal           = db.Animals.Where(u => u.ID == animal.ID).First();

            foreach (KeyValuePair <int, string> item in updates)
            {
                if (item.Key == 2)
                {
                    var breedExists = db.Breeds.Where(b => b.breed1 == item.Value).First();
                    if (breedExists != null)
                    {
                        breedExists.breed1 = item.Value;
                        db.Breeds.InsertOnSubmit(breedExists);
                    }
                    else
                    {
                        var newCategory = UserInterface.EnterSearchCriteria(updates, "1");
                        foreach (KeyValuePair <int, string> species in newCategory)
                        {
                            var categoryExists = db.Catagories.Where(c => c.catagory1 == species.Value).First();
                            if (categoryExists != null)
                            {
                                categoryExists.catagory1 = species.Value;
                                db.Catagories.InsertOnSubmit(categoryExists);
                            }
                            else
                            {
                                updatedAnimal.Breed1.Catagory1.catagory1 = species.Value;
                            }
                            updatedAnimal.Breed1.breed1 = item.Value;
                        }
                    }
                }
                else if (item.Key == 3)
                {
                    updatedAnimal.name = item.Value;
                }
                else if (item.Key == 4)
                {
                    updatedAnimal.age = Convert.ToInt32(item.Value);
                }
                else if (item.Key == 5)
                {
                    updatedAnimal.demeanor = item.Value;
                }
                else if (item.Key == 6)
                {
                    updatedAnimal.kidFriendly = Convert.ToBoolean(item.Value);
                }
                else if (item.Key == 7)
                {
                    updatedAnimal.petFriendly = Convert.ToBoolean(item.Value);
                }
                else if (item.Key == 8)
                {
                    updatedAnimal.weight = Convert.ToInt32(item.Value);
                }
                else
                {
                    break;
                }
            }
            db.Animals.InsertOnSubmit(updatedAnimal);
            db.SubmitChanges();
        }