示例#1
0
 public ActionResult Search(Guid?animalTypeID)
 {
     if (animalTypeID != null)
     {
         List <Pet> pets = new List <Pet>();
         foreach (var pet in _petRepository.GetAllPets().Where(x => x.AnimalTypeId == animalTypeID).Take(10).ToList())
         {
             pets.Add(new Pet()
             {
                 PetID       = pet.Id,
                 Name        = pet.Name,
                 DateOfBirth = pet.DateOfBirth,
                 Description = pet.Description,
                 Weight      = pet.Weight,
                 AnimalType  = pet.AnimalType
             });
         }
         var model = new PetListing()
         {
             AnimalTypes = new SelectList(_animalRepository.GetAllAnimalTypes(), "AnimalTypeID", "Name"),
             Pets        = pets
         };
         return(PartialView("_PetList", model));
     }
     return(HttpNotFound());
 }
示例#2
0
        public ActionResult Index()
        {
            List <Pet> pets = new List <Pet>();

            foreach (var pet in _petRepository.GetAllPets())
            {
                pets.Add(new Pet()
                {
                    PetID       = pet.Id,
                    Name        = pet.Name,
                    DateOfBirth = pet.DateOfBirth,
                    Description = pet.Description,
                    Weight      = pet.Weight,
                    AnimalType  = pet.AnimalType
                });
            }

            var model = new PetListing()
            {
                Pets        = pets,
                AnimalTypes = new SelectList(_animalRepository.GetAllAnimalTypes(), "AnimalTypeID", "Name")
            };

            return(View(model));
        }