Example #1
0
        public void Can_read_as_Cat_from_Dog_with_typeinfo()
        {
            var petDog = new PetDog { Dog = new Dog { Name = "Woof!" } };
            var json = petDog.ToJson();

            Console.WriteLine(json);

            var weirdCat = json.FromJson<WeirdCat>();

            Assert.That(weirdCat.Dog, Is.Not.Null);
            Assert.That(weirdCat.Dog.Name, Is.EqualTo(petDog.Dog.Name));
        }
        // GET: PetDogs/Details/5
        public ViewResult Details(int?id)
        {
            if (id == null)
            {
                return(View("Error"));
            }
            PetDog petDog = db.PetDogs.FirstOrDefault(d => d.DogId == id);

            if (petDog == null)
            {
                return(View("Error"));
            }
            return(View(petDog));
        }
        public PetDog Save(PetDog dog)
        {
            if (dog.DogId == 0)
            {
                db.PetDogs.Add(dog);
            }
            else
            {
                db.Entry(dog).State = System.Data.Entity.EntityState.Modified;
            }

            db.SaveChanges();
            return(dog);
        }
        public ViewResult DeleteConfirmed(int?id)
        {
            if (id == null)
            {
                return(View("Error"));
            }

            PetDog petDog = db.PetDogs.FirstOrDefault(d => d.DogId == id);

            if (petDog == null)
            {
                return(View("Error"));
            }

            db.Delete(petDog);
            return(View("Index"));
        }
Example #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("OOP example");
            var dog = new PetDog("Ace", new PetColor("Black"));

            Console.WriteLine(dog.MyPet());
            Console.ReadLine();

            var cat = new PetCat("Clementine", new PetColor("Brown"));

            Console.WriteLine(cat.MyPet());


            PetFeeder.FeedPet(cat, new Kibble());

            Console.ReadLine();
            Console.Beep();
        }
		public void Can_read_as_Cat_from_Dog_with_typeinfo()
		{
			var petDog = new PetDog { Dog = new Dog { Name = "Woof!" } };
			var json = petDog.ToJson();

			Console.WriteLine(json);

			var weirdCat = json.FromJson<WeirdCat>();

			Assert.That(weirdCat.Dog, Is.Not.Null);
			Assert.That(weirdCat.Dog.Name, Is.EqualTo(petDog.Dog.Name));
		}
 public void Delete(PetDog dog)
 {
     db.PetDogs.Remove(dog);
     db.SaveChanges();
 }