// GET: Animals/Create public ActionResult Create() { //ViewBag.AnimalTypeID = new SelectList(db.AnimalTypes, "id", "AnimalTypeName"); //ViewBag.FosterID = new SelectList(db.Locations.Where(o => o.isFoster == true && o.isActive == true).OrderBy(o => o.name), "id", "name"); var animalTypes = db.AnimalTypes.ToList(); var fosterLocations = db.Locations .ToList() .Where(o => o.isFoster == true && o.isActive == true) .OrderBy(o => o.name); var pullLocations = db.Locations .ToList() .Where(o => o.isPullLocation == true); var sexes = db.Sexes.ToList(); var microchipMaunf = db.Medications .Where(e => e.isMicrochipManufacturer); //SelectList FosterIDs = new SelectList(); //FosterIDs. var viewModel = new NewAnimalViewModel { AnimalTypes = animalTypes, FosterLocations = fosterLocations, PullLocations = pullLocations, Sexes = sexes, MicrochipManufactures = microchipMaunf }; return(View(viewModel)); }
public IActionResult New(NewAnimalViewModel newAnimalViewModel) { // TODO #6 - Validate the ViewModel and if valid, create a // new Animal and add it to the AnimalData data store. Then // redirect to the Animal detail (Index) action/view for the new Animal if (ModelState.IsValid) { Animal newAnimal = new Animal { Name = newAnimalViewModel.Name, Size = animalData.Sizes.Find(newAnimalViewModel.SizeID), Origin = animalData.Origins.Find(newAnimalViewModel.OriginID), Eat = animalData.Eats.Find(newAnimalViewModel.EatID), Kind = animalData.Kinds.Find(newAnimalViewModel.KindID) }; animalData.Animals.Add(newAnimal); return(Redirect(String.Format("/animal?id={0}", newAnimal.ID))); } //AnimalData data = AnimalData.GetInstance(); //Animal newAnimal = new Animal(); //newAnimal.Employer = data.Employers.Find(newAnimalViewModel.EmployerID.ID); return(View(newAnimalViewModel)); }
// The detail display for a given Animal at URLs like /Animal?id=17 public IActionResult Index(int id) { //TODO #1 - get the Animal with the given ID and pass it into the view Animal findAnimal = animalData.Find(id); NewAnimalViewModel displayAnimal = new NewAnimalViewModel { Name = findAnimal.Name, SizeID = findAnimal.Size.ID, OriginID = findAnimal.Origin.ID, KindID = findAnimal.Kind.ID, EatID = findAnimal.Eat.ID }; return(View(findAnimal)); }
public IActionResult New() { NewAnimalViewModel newAnimalViewModel = new NewAnimalViewModel(); return(View(newAnimalViewModel)); }