Exemple #1
0
        internal static void EnterAnimalUpdate(Animal animals, Dictionary <int, string> updates)
        {
            HumaneSocietyDataContext db = new HumaneSocietyDataContext();
            Room room = new Room();

            animals = db.Animals.Where(a => a.AnimalId == animals.AnimalId).FirstOrDefault();
            if (animals.AdoptionStatus.ToLower() == "adopted")
            {
                Console.WriteLine("This animal has been adopted. No changes can be made. Press any key to continue.");
                Console.ReadLine();
                return;
            }
            foreach (KeyValuePair <int, string> criteria in updates)
            {
                switch (criteria.Key)
                {
                case 1:
                    animals.CategoryId = int.Parse(criteria.Value);
                    break;

                case 2:
                    animals.Name = criteria.Value;
                    break;

                case 3:
                    animals.Age = int.Parse(criteria.Value);
                    break;

                case 4:
                    animals.Demeanor = criteria.Value;
                    break;

                case 5:
                    if (criteria.Value.ToLower() == "true")
                    {
                        animals.KidFriendly = true;
                    }
                    else
                    {
                        animals.KidFriendly = false;
                    }
                    break;

                case 6:
                    if (criteria.Value.ToLower() == "true")
                    {
                        animals.PetFriendly = true;
                    }
                    else
                    {
                        animals.PetFriendly = false;
                    }
                    break;

                case 7:
                    animals.Weight = int.Parse(criteria.Value);
                    break;
                }
            }
            try
            {
                db.SubmitChanges();
                UserInterface.DisplayUserOptions("Update complete.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemple #2
0
        internal static void AddNewClient(string firstName, string lastName, string username, string password, string email, string streetAddress, int zipCode, int stateId)
        {
            Client newClient = new Client();

            newClient.FirstName = firstName;
            newClient.LastName  = lastName;
            newClient.UserName  = username;
            newClient.Password  = password;
            newClient.Email     = email;

            Address addressFromDb = db.Addresses.Where(a => a.AddressLine1 == streetAddress && a.Zipcode == zipCode && a.USStateId == stateId).FirstOrDefault();

            // if the address isn't found in the Db, create and insert it
            if (addressFromDb == null)
            {
                Address newAddress = new Address();
                newAddress.AddressLine1 = streetAddress;
                newAddress.City         = null;
                newAddress.USStateId    = stateId;
                newAddress.Zipcode      = zipCode;

                db.Addresses.InsertOnSubmit(newAddress);
                db.SubmitChanges();

                addressFromDb = newAddress;
            }

            // attach AddressId to clientFromDb.AddressId
            newClient.AddressId = addressFromDb.AddressId;

            db.Clients.InsertOnSubmit(newClient);

            db.SubmitChanges();
        }
Exemple #3
0
        internal static void RunEmployeeQueries(Employee employee, string v)
        {
            HumaneSocietyDataContext db = new HumaneSocietyDataContext();

            switch (v)
            {
            case "delete":
                List <Animal> animals = db.Animals.Where(a => a.EmployeeId == employee.EmployeeNumber).ToList();
                employee = db.Employees.Where(e => e.EmployeeNumber == employee.EmployeeNumber).FirstOrDefault();
                foreach (Animal pets in animals)
                {
                    pets.EmployeeId = null;
                }

                db.Employees.DeleteOnSubmit(employee);
                try
                {
                    db.SubmitChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                break;

            case "read":
                employee = db.Employees.Where(e => e.EmployeeNumber == employee.EmployeeNumber).FirstOrDefault();
                UserInterface.DisplayUserOptions(" First Name: " + employee.FirstName + "\n Last Name: " + employee.LastName + "\n UserName: "******"\n Password: "******"\n Employee Nmber: " + employee.EmployeeNumber + "\n Email: " + employee.Email + "\n Press any key to continue.");
                Console.ReadLine();
                break;

            case "update":
                Employee updatedEmployee = db.Employees.Where(e => e.EmployeeNumber == employee.EmployeeNumber).FirstOrDefault();
                updatedEmployee.FirstName      = employee.FirstName;
                updatedEmployee.LastName       = employee.LastName;
                updatedEmployee.EmployeeNumber = employee.EmployeeNumber;
                updatedEmployee.Email          = employee.Email;

                break;

            case "create":
                Employee newEmployee = new Employee();
                newEmployee = db.Employees.Where(e => e.EmployeeNumber == employee.EmployeeNumber).FirstOrDefault();
                if (newEmployee == null)
                {
                    db.Employees.InsertOnSubmit(employee);
                    UserInterface.DisplayUserOptions("Employee addition successful. Press any key to continue.");
                    Console.ReadLine();
                }
                else
                {
                    UserInterface.DisplayUserOptions("That employee number is already in use, press any key to go back to the main menu.");
                    Console.ReadLine();
                }
                break;
            }
            try
            {
                db.SubmitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemple #4
0
        //=======================================================================================================================

        internal static void UpdateAdoption(bool v, Adoption adoption)
        {
            db.Adoptions.Where(x => x.PaymentCollected == v && x.AnimalId == adoption.AdoptionId).SingleOrDefault();
            db.SubmitChanges();
        }
Exemple #5
0
        public static void RunEmployeeQueryUpdate(Employee employee)
        {
            Employee employeeToBeUpdated = (from n in context.Employees where n.EmployeeId == employee.EmployeeId select n).First();

            Console.WriteLine($"What would you like to update? 1. Employee First Name 2. Employee Last Name 3. Employee User Name 4. Employee Password 5. Employee Number 6. Employee Email");
            string userInput = Console.ReadLine();

            switch (userInput)
            {
            case "1":
                UpdateEmployeeFirstName(employeeToBeUpdated);
                break;

            case "2":
                UpdateEmployeeLastName(employeeToBeUpdated);
                break;

            case "3":
                UpdateEmployeeUserName(employeeToBeUpdated);
                break;

            case "4":
                UpdateEmployeePassword(employeeToBeUpdated);
                break;

            case "5":
                UpdateEmployeeEmployeeNumber(employeeToBeUpdated);
                break;

            case "6":
                UpdateEmployeeEmail(employeeToBeUpdated);
                break;

            default:
                Console.WriteLine("Please enter a valid command of 1-6.");
                Console.ReadLine();
                RunEmployeeQueryUpdate(employee);
                break;
            }

            context.SubmitChanges();
        }
        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();
        }
Exemple #7
0
 public PopulateDB()
 {
     db.Employees.InsertOnSubmit(steveEmployee);
     db.SubmitChanges();
 }