Exemple #1
0
        public IActionResult Create(AnimalCatVM vm)
        {
            if (ModelState.IsValid)
            {
                ViewBag.Thanks  = vm.Cat.Name;
                ViewBag.Cat     = vm.Cat;
                ViewBag.Species = speciesRepository.Get(vm.Cat.SpeciesId);

                animalRepository.Save(vm.Cat);

                string searchString = null;

                if (vm.Cat.Gender.Value == Gender.Male)
                {
                    searchString = "1";
                }
                if (vm.Cat.Gender.Value == Gender.Female)
                {
                    searchString = "0";
                }
                List <Cat> cats = this.animalRepository.Find(searchString);
                return(View("Thanks", cats));
            }

            return(View(ViewModelCreator.CreateAnimalCatVm(speciesRepository)));
        }
        public IActionResult Create(AnimalCatVM vm)
        {
            if (ModelState.IsValid)
            {
                ViewBag.Thanks  = vm.Cat.Name;
                ViewBag.Cat     = vm.Cat;
                ViewBag.Species = speciesRepository.Get(vm.Cat.SpeciesId); //The species ID is the only thing known, not the name of the actual species object. Therefore we get it from the species repo

                animalRepository.Save(vm.Cat);

                string searchString = null;

                if (vm.Cat.Gender.Value == Gender.Male) //This will ensure that the cats shown to the newly created cat will be the opposite gender.
                {
                    searchString = "1";
                }
                if (vm.Cat.Gender.Value == Gender.Female) //Apparently you can do this to compare enums
                {
                    searchString = "0";
                }
                List <Cat> cats = this.animalRepository.Find(searchString);
                return(View("Thanks", cats));
            }

            return(View(ViewModelCreator.CreateAnimalCatVm(speciesRepository)));
        }
Exemple #3
0
 public static AnimalCatVM CreateAnimalCatVm(ISpeciesRepository speciesRepository)
 {
     return(new AnimalCatVM()
     {
         Cat = new Cat(),
         SpeciesSelectList = new SelectList(speciesRepository.Get(), "SpeciesId", "Name")
     });
 }
 public static CatDetailsView CreateAnimalCatVm(ISpeciesRepository speciesRepository)
 {
     return(new CatDetailsView()
     {
         cat = new Cat(),
         speciesList = new SelectList(speciesRepository.Get(), "SpeciesId", "Name")
     });
 }
        public IActionResult Edit(int id)
        {
            var viewModel   = new AnimalSpeciesViewModel();
            var speciesList = ISpeciesRepo.Get();

            viewModel.SpeciesSelectList = new SelectList(speciesList, "SpeciesId", "Name");
            viewModel.Cat = IRepo.Get(id);
            return(View(viewModel));
        }
Exemple #6
0
        public IHttpActionResult Get()
        {
            IHttpActionResult     result;
            IEnumerable <Species> speciesTypeList = repository.Get();

            result = Json <IEnumerable <Species> >(speciesTypeList);

            return(result);
        }
Exemple #7
0
        public static AnimalSpeciesViewModel CreateAnimalCatVm(ISpeciesRepository speciesRepository)
        {
            var viewModel = new AnimalSpeciesViewModel()
            {
                Cat = new Cat(),
                SpeciesSelectList = new SelectList(speciesRepository.Get(), "SpeciesId", "Name")
            };

            return(viewModel);
        }
 // GET: Species
 public IActionResult Index()
 {
     return(View(speciesRepository.Get()));
 }
Exemple #9
0
 // GET: Species
 public IActionResult Index() //Should not be asynchronous
 {
     return(View(repo.Get()));
 }
Exemple #10
0
 // GET: Species
 public IActionResult Index()
 {
     return(View(repo.Get()));
 }