예제 #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)));
        }
예제 #2
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); //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)));
        }
예제 #3
0
        public IActionResult Details(int id)
        {
            Cat         cat = animalRepository.Get(id);
            AnimalCatVM vm  = ViewModelCreator.CreateAnimalCatVm(speciesRepository);

            vm.Cat = cat;

            return(View(vm));
        }
        public IActionResult Create(AnimalCatVM vm)
        {
            if (ModelState.IsValid)
            {
                ViewBag.Thanks = vm.Cat.Name;
                ViewBag.Cat    = vm.Cat;

                animalRepository.Save(vm.Cat);

                return(View("Thanks", vm.Cat));
            }

            return(View(ViewModelCreator.CreateAnimalCatVm(speciesRepository)));
        }
예제 #5
0
        public IActionResult Edit(int id)
        {
            // Create an edit view
            // Look up cat object from catId in the database
            // Show an edit view to the user, displaying the cat object
            Cat         cat = animalRepository.Get(id);
            AnimalCatVM vm  = ViewModelCreator.CreateAnimalCatVm(speciesRepository);

            vm.Cat = cat;



            return(View(vm));
        }
예제 #6
0
        public IActionResult Create(CatDetailsView CatDW)
        {
            if (ModelState.IsValid)
            {
                ViewBag.cat    = CatDW.cat;
                ViewBag.Thanks = CatDW.cat.Name;

                IAnimalRepo.Save(CatDW.cat);
                var OppositeCats = IAnimalRepo.OppositeCat(CatDW.cat);

                return(View("Thanks", OppositeCats.ToList()));
            }
            return(View(ViewModelCreator.CreateAnimalCatVm(SpeciesRepo)));
        }
예제 #7
0
 public IActionResult Create()
 {
     return(View(ViewModelCreator.CreateAnimalCatVm(speciesRepository)));
 }