Exemplo n.º 1
0
        public AddAnimal modelMaker()
        {
            AddAnimal Obj = new AddAnimal();

            Obj.familyNames      = GetFamilyNames();
            Obj.emplyeeUserNames = ViewMyEmployees();
            Obj.exhibitNames     = GetExihibitNames();
            Obj.attrNames        = GetAttrNames();
            List <char> sex = new List <char>();

            sex.Add('M'); sex.Add('F');
            Obj.sexs = sex;
            return(Obj);
        }
Exemplo n.º 2
0
        }     //end AdopterMainMenu

        public void EmployeeMainMenu()
        {
            Console.WriteLine("Humane Society Employee Portal");
            Console.WriteLine("Here you can add a single animal, import animals from a csv file,\n or search an animal to view info, manage details, and complete adoption");
            Console.WriteLine("Your Options are as follows:");
            Console.WriteLine("1\tor\tADD\n2\tor\tIMPORT\n3\tor\tSEARCH");
            empMenuInput = Console.ReadLine().ToUpper();
            switch (empMenuInput)
            {
            case "1":
            case "ADD":
                Console.WriteLine("You have selected to add a single animal, press any key to continue");
                Console.ReadKey();
                AddAnimal addAnimal = new AddAnimal();
                break;

            case "2":
            case "IMPORT":
                Console.WriteLine("You have selected to import from a csv, press any key to continue");
                Console.ReadKey();
                break;

            case "3":
            case "SEARCH":
                Console.WriteLine("You have selected to search an animal, press any key to continue");
                Console.ReadKey();
                Search eSearch = new Search();
                eSearch.SearchAnimal();
                break;

            default:
                Console.WriteLine("Your input was not recognized, press any key to return to the main menu");
                Console.ReadKey();
                EmployeeMainMenu();
                break;
            }
        } //End Employee Main Menu
Exemplo n.º 3
0
        public ActionResult AddAnimal(AddAnimal model, DateTime?dob)
        {
            using (team4zooEntities db = new team4zooEntities())
            {
                try
                {
                    Animal animal = new Animal();
                    animal.Animal_ID   = Guid.NewGuid();
                    animal.animal_name = model.name;
                    animal.dob         = dob;
                    animal.sex         = model.sex;
                    animal.weight      = model.weight;
                    animal.owner       = model.owner;
                    animal.isActive    = true;
                    animal.family      = db.Family_Name.Where(x => x.family_title == model.familyN).Select(y => y.Family_ID).FirstOrDefault();
                    if (model.name == null || model.sex == null || model.weight.Equals(null) ||
                        model.weight.Equals(0.00) || !dob.HasValue || model.owner == null || model.ExhibitN == null)
                    {
                        AddAnimal newModel = modelMaker();
                        newModel.ErrorMessage1 = "Please, Fill all required fields.";
                        return(View("~/Views/AddAnimal/Index.cshtml", newModel));
                    }
                    else if (CheckExistingName(model.name))
                    {
                        AddAnimal newModel = modelMaker();
                        newModel.ErrorMessage2 = "This Name Already Exists.";
                        return(View("~/Views/AddAnimal/Index.cshtml", newModel));
                    }
                    else
                    {
                        if (model.AttrN != null)
                        {
                            animal.Attraction_ID = db.Attractions.Where(x => x.attraction_name == model.AttrN).Select(y => y.Attraction_ID).FirstOrDefault();
                        }
                        animal.Exhibit_ID   = db.Exhibits.Where(x => x.exhibit_name == model.ExhibitN).Select(y => y.Exhibit_ID).FirstOrDefault();
                        animal.Assignee1_ID = db.Employees.Where(x => x.username == model.Assignee1).Select(y => y.Employee_ID).FirstOrDefault();
                        animal.Assignee2_ID = db.Employees.Where(x => x.username == model.Assignee2).Select(y => y.Employee_ID).FirstOrDefault();
                        animal.Assignee3_ID = db.Employees.Where(x => x.username == model.Assginee3).Select(y => y.Employee_ID).FirstOrDefault();

                        db.Animals.Add(animal);
                        db.SaveChanges();
                        return(RedirectToAction("Index", "AddAnimal"));
                    }
                }

                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
            }
        }