private void AddNewAnimalToDatabase() { try { Animal animal = new Animal(); Trait traits = new Trait(); Health health = new Health(); UserInterface.DisplayIntroToAddingAnAnimal(); UserInterface.PressAnyKeyToContinue(); animal.type = UserInterface.AskTypeOfAnimal(); animal.gender = UserInterface.AskGenderOfAnimal(); animal.name = UserInterface.AskNameOfAnimal(); animal.breed = UserInterface.AskBreedOfAnimal(); animal.price = UserInterface.AskPriceOfAnimal(); animal.entryDate = DateTime.Now; animal.adopted = false; animal.age = UserInterface.AskAgeOfAnimal(); traits.size = UserInterface.AskSizeOfAnimal(); traits.color = UserInterface.AskColorOfAnimal(); traits.activityLevel = UserInterface.AskActivityLevelOfAnimal(); health.foodConsumptionPerWeek = UserInterface.AskAboutFoodConsumptionOfAnimal(); health.receivedShots = true; UserInterface.AskIfShotsAreUpToDateOnAnimal(); string choice = UserInterface.ConfirmTheAdditionOfTheAnimal(); if (choice == "yes") { db.Animals.InsertOnSubmit(animal); db.SubmitChanges(); Room firstRoom = FindFirstRoomAvailableToAddNewAnimalTo(); AssignRoomVariables(firstRoom, animal.animalId, traits.size); traits.animalId = animal.animalId; health.animalId = animal.animalId; db.Traits.InsertOnSubmit(traits); db.Healths.InsertOnSubmit(health); db.SubmitChanges(); UserInterface.PressAnyKeyToContinue(); DecideWhatToDoAsAnEmployee(); } else if (choice == "no") { DecideWhatToDoAsAnEmployee(); } else { UserInterface.DisplayWrongKeyTyped(); AddNewAnimalToDatabase(); } } catch (Exception e) { Console.WriteLine(e); UserInterface.DisplayWrongKeyTyped(); AddNewAnimalToDatabase(); } }
private Adopter AskAdopterFormQuestions() { UserInterface.PrepareAdopterForQuestions(); Adopter adopter = new Adopter(); adopter.firstName = UserInterface.AskForAdopterFirstName(); adopter.lastName = UserInterface.AskForAdopterLastName(); adopter.password = UserInterface.AskForAdopterPassword(); adopter.phoneNumber = UserInterface.AskForAdopterPhoneNumber(); adopter.email = UserInterface.AskForAdopterEmail(); adopter.married = UserInterface.AskIfAdopterIsMarried(); adopter.hasKids = UserInterface.AskIfAdopterHasChildren(); adopter.paidAdoptionFee = false; db.Adopters.InsertOnSubmit(adopter); db.SubmitChanges(); return(adopter); }
public void ImportCSV(string file) { LINQtoSQLDataContext db = new LINQtoSQLDataContext(); var imported = ReadCSV(file); foreach (var input in imported) { Animal animal = new Animal(); Trait traits = new Trait(); Health health = new Health(); animal.name = input[0]; animal.breed = input[1]; animal.age = int.Parse(input[2]); animal.price = double.Parse(input[3]); animal.entryDate = DateTime.Now; animal.adopted = false; animal.type = input[4]; animal.gender = input[5]; traits.size = input[6]; traits.activityLevel = input[7]; traits.color = input[8]; health.receivedShots = true; health.foodConsumptionPerWeek = decimal.Parse(input[9]); db.Animals.InsertOnSubmit(animal); db.SubmitChanges(); traits.animalId = animal.animalId; health.animalId = animal.animalId; db.Traits.InsertOnSubmit(traits); db.Healths.InsertOnSubmit(health); Room roomForTransferAnimal = LocateCorrectRoomToAssignToNewAnimal(); UpdateRoomVariables(roomForTransferAnimal, animal.animalId, traits.size); db.SubmitChanges(); } Console.WriteLine("The file of new animals was successfully added to the database.\n\n\n"); }