示例#1
0
        public void TestPetRepository()
        {
            Assert.AreEqual(0, petsRepository.Size());

            Pet pet1 = new Pet()
            {
                ID      = 1,
                Name    = "kiki",
                Age     = 12,
                Gender  = GenderEnum.FEMININ,
                Species = "koala"
            };

            Pet pet2 = new Pet()
            {
                ID      = 2,
                Name    = "mimi",
                Age     = 2,
                Gender  = GenderEnum.FEMININ,
                Species = "cat"
            };

            //test the save function
            petsRepository.Save(pet1);
            petsRepository.Save(pet2);
            Assert.AreEqual(2, petsRepository.Size());

            //test the find all
            List <Pet> allPets = new List <Pet>();

            foreach (Pet pet in petsRepository.FindAll())
            {
                allPets.Add(pet);
            }
            Assert.AreEqual(allPets[0].ID, 1);
            Assert.AreEqual(allPets[1].ID, 2);

            //test the find one
            Pet petFound = petsRepository.FindOne(1);

            Assert.AreEqual(petFound, pet1);
        }
示例#2
0
        public virtual ActionResult Edit(EditVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            UnitOfWork         uow    = new UnitOfWork();
            PetsRepository     Repo   = new PetsRepository(uow);
            VaccinesRepository V_repo = new VaccinesRepository(uow);

            Pet     item = new Pet();
            Vaccine vac  = new Vaccine();

            item.Vaccines = new List <Vaccine>();
            model.PopulateEntity(item);

            item.Vaccines.Clear();

            foreach (var v in model.Selected)
            {
                vac = V_repo.GetById(v.ID);
                if (v.IsChecked)
                {
                    vac.Pet.Remove(item);

                    item.Vaccines.Add(vac);
                    vac.Pet.Add(item);
                }
            }
            //List<Vaccine> vacs = new List<Vaccine>();

            /* foreach (var v in model.Selected)
             * {
             *   if (v.IsChecked)
             *   {
             *       Vaccine sel = new Vaccine();
             *       sel = v_repo.GetById(v.ID);
             *       vacs.Add(sel);
             *   }
             * }
             * foreach (var v in vacs)
             * {
             *   v_repo.Save(v);
             * }*/

            Repo.Save(item);

            uow.Commit();
            //return View(model);
            return(RedirectToAction("Index", "Pet"));
        }
示例#3
0
        //PET FUNCTIONALITIES
        public Pet savePet(string name, int age, GenderEnum gender, string species)
        {
            Pet petToSave = new Pet()
            {
                ID      = idGenerator <Pet>(petsRepository),
                Name    = name,
                Age     = age,
                Gender  = gender,
                Species = species
            };

            return(petsRepository.Save(petToSave));
        }