Пример #1
0
        private static void RetrieveDataWithFind()
        {
            var keyval = 3;

            using (NinjaContext context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;
                Ninja ninja = context.Ninjas.Find(keyval);

                Console.WriteLine("I have found this record in database " + ninja.Name);

                Ninja ninja1 = context.Ninjas.Find(keyval);
                Console.WriteLine("I have found in memory this " + ninja1.Name);
                ninja = null;
            }
        }
        private static void InsertNinja()
        {
            var ninja = new Ninja {
                Name             = "HuySonSan",
                ServedInOniwaban = false,
                DateOfBirth      = new DateTime(1987, 11, 20),
                ClanId           = 1
            };

            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;
                context.Ninjas.Add(ninja);
                context.SaveChanges();
            }
        }
Пример #3
0
        private static void InsertNinja()
        {
            var ninja = new Ninja
            {
                Name             = "SampsonSan",
                ServedInOniwaban = false,
                //DateOfBirth = new DateTime(2008, 1, 28),
                ClanId = 1
            };

            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;//LD useful to see what's app in the database
                context.Ninjas.Add(ninja);
                context.SaveChanges();
            }
        }
Пример #4
0
        private static void InsertNinja()
        {
            var ninja = new Ninja
            {
                Name = "Raed Ninja",
                ServedInOniwabanValue = 0,
                DateOfBirth           = new System.DateTime(1970, 1, 1),
                ClanId = 1
            };

            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;
                context.Ninjas.Add(ninja);
                context.SaveChanges();
            }
        }
Пример #5
0
        private static void insertNinja()
        {
            var ninja = new Ninja
            {
                clanId      = 1,
                served      = false,
                dateOfBirth = new DateTime(1988, 09, 09),
                name        = "Abderrahmane"
            };

            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;
                context.ninjas.Add(ninja);
                context.SaveChanges();
            }
        }
Пример #6
0
        private static void InsertNinja()
        {
            var ninja = new Ninja
            {
                Name             = "SampsonSan",
                ServedInOniwaban = false,
                DateOfBirth      = new DateTime(2008, 1, 28),
                ClanId           = 1
            };

            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine; //logging ef6 feature
                context.Ninjas.Add(ninja);
                context.SaveChanges();
            }
        }
Пример #7
0
        private static void InsetNinja()
        {
            var ninja = new Ninja
            {
                Name             = "JulieSan",
                ServedinOniwaban = false,
                DateOfBirth      = new DateTime(1980, 1, 1),
                ClanID           = 1
            };

            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;
                context.Ninjas.Add(ninja);
                context.SaveChanges();
            };
        }
Пример #8
0
        private static void InsertNinja()
        {
            var ninja = new Ninja
            {
                Name             = "SampsonSan",
                ServedInOniwaban = false,
                DateOfBirth      = new DateTime(2008, 1, 28),
                ClanId           = 1
            };

            using (var context = new NinjaContext()) //insert ninja object to database by instantiating NinjaContext which has DbSet<Ninja> allowing to interact with DB
            {
                //context.Database.Log = Console.WriteLine;
                context.Ninjas.Add(ninja); //in Ninjas DbSet(table) in 'context' NinjaContext(DB) add the details on Ninja
                context.SaveChanges();
            }
        }
Пример #9
0
        private static void InsertNinja()
        {
            Ninja ninja = new Ninja()
            {
                Name             = "Alexey",
                ServedInOniwaban = false,
                DateOfBirth      = new DateTime(1980, 10, 13),
                ClainId          = 1
            };

            using (NinjaContext context = new NinjaContext())
            {
                Database.SetInitializer(new NullDatabaseInitializer <NinjaContext>());  //avoid the initialization of the database in case database already exists in production
                context.Database.Log = Console.WriteLine;
                context.Ninjas.Add(ninja);
                context.SaveChanges();
            }
        }
Пример #10
0
        private static void InsertNinja()
        {
            var ninja = new Ninja
            {
                Name             = "NinkaSan",
                ServedInOniwaban = true,
                DateOfBirth      = new DateTime(1992, 4, 20),
                ClanId           = 1
            };

            //using entity framework to insert the object
            using (var context = new NinjaContext())
            {
                //context.Database.Log = Console.WriteLine;
                context.Ninjas.Add(ninja);
                context.SaveChanges();
            }
        }//InsertNinja()
Пример #11
0
        private static void InsertNinja()
        {
            var clan = new Clan
            {
                ClanName = "Vermont Ninjas",
                Id       = 1
            };

            var ninja0 = new Ninja
            {
                Name             = "JulieSan",
                ServedInOniwaban = false,
                DateOfBirth      = new DateTime(1980, 1, 1),
                Clan             = clan
            };
            var ninja1 = new Ninja
            {
                Name             = "SampsonSan",
                ServedInOniwaban = false,
                DateOfBirth      = new DateTime(2008, 1, 28),
                Clan             = clan
            };
            var ninja2 = new Ninja
            {
                Name             = "Leonardo",
                ServedInOniwaban = false,
                DateOfBirth      = new DateTime(1985, 11, 11),
                Clan             = clan
            };
            var ninja3 = new Ninja
            {
                Name             = "Raphael",
                ServedInOniwaban = false,
                DateOfBirth      = new DateTime(1985, 11, 5),
                Clan             = clan
            };

            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;
                context.Ninjas.AddRange(new Ninja[] { ninja0, ninja1, ninja2, ninja3 });
                context.SaveChanges();
            }
        }
Пример #12
0
        private static void InsertNinja()
        {
            Ninja ninja = new Ninja
            {
                Name             = "SampsonSan",
                ServedInOniwaban = false,
                DateOfBirth      = new DateTime(2008, 1, 28),
                ClanId           = 1
            };

            // uses entity framework to add the local ninja obj
            using (NinjaContext context = new NinjaContext())
            {
                // logging
                context.Database.Log = Console.WriteLine;
                context.Ninjas.Add(ninja);
                context.SaveChanges();
            }
        }
Пример #13
0
        private static void RetrieveDataWithFind()
        {
            int keyval = 4;

            using (NinjaContext context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;
                Ninja ninja = context.Ninjas.Find(keyval);
                Console.WriteLine($"After Find1: {ninja.Name}");

                // if the object is in memory, it will not query
                // the db a second time. great for performance
                // EF does this automagically.
                Ninja someNinja = context.Ninjas.Find(keyval);
                Console.WriteLine($"After Find2: {someNinja.Name}");

                ninja = null;
            }
        }
Пример #14
0
        private static void InsertMultipleNinjas()
        {
            var ninja1 = new Ninja {
                Name = "Lenoanrdo", ServerInOniwaban = false, DateOfBirth = new DateTime(1984, 1, 1), ClanId = 1
            };
            var ninja2 = new Ninja {
                Name = "Rapheal", ServerInOniwaban = false, DateOfBirth = new DateTime(1985, 1, 1), ClanId = 1
            };

            using (var context = new NinjaContext())
            {
                var ninlist = new List <Ninja> {
                    ninja1, ninja2
                };
                context.Database.Log = Console.WriteLine;
                context.Ninjas.AddRange(ninlist);
                context.SaveChanges();
            }
        }
Пример #15
0
        private static void InsertNinja()
        {
            var ninja = new Ninja
            {
                Name             = "Sonia",
                ServedInOniwaban = false,
                DateOfBirth      = new DateTime(1972, 12, 27),
                ClanID           = 1
            };

            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;
                context.Ninjas.Add(ninja);
                context.SaveChanges();
            };

            Console.ReadLine();
        }
Пример #16
0
        public static void Main(string[] args)
        {
            Human  Cindy    = new Human("Cindy");
            Wizard Hermione = new Wizard("Hermione");
            Wizard Harry    = new Wizard("Harry");

            Hermione.Heal(Harry);
            Harry.FireBall(Hermione);
            Hermione.FireBall(Harry);
            Hermione.FireBall(Harry);
            Ninja Donnie = new Ninja("Donnie");

            Donnie.Steal(Harry);
            Donnie.GetAway();
            Samurai Lee = new Samurai("Lee");

            Lee.DeathBlow(Harry);
            Lee.Meditate();
        }
Пример #17
0
        private static void InsertMultipleNinjas()
        {
            var ninja1 = new Ninja
            {
                Name             = "Leonardo",
                ServedInOniwaban = false,
                DateOfBirth      = new DateTime(1984, 1, 1),
                ClanId           = 1
            };

            var ninja2 = new Ninja
            {
                Name             = "Raphael",
                ServedInOniwaban = false,
                DateOfBirth      = new DateTime(1985, 1, 1),
                ClanId           = 1
            };

            //var ninja3 = new Ninja
            //{
            //    Name = "Michelangelo",
            //    ServedInOniwaban = false,
            //    ClanId = 1,
            //    DateOfBirth = new DateTime(1986, 9, 24)
            //};

            //var ninja4 = new Ninja
            //{
            //    Name = "Michelangelo",
            //    ServedInOniwaban = false,
            //    ClanId = 1,
            //    DateOfBirth = new DateTime(1986, 9, 24)
            //};

            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.Write;
                context.Ninjas.AddRange(new List <Ninja> {
                    ninja1, ninja2
                });
                context.SaveChanges();
            }
        }
        private static void InsertNinjaWithEquipment()
        {
            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;

                var ninja = new Ninja()
                {
                    Name             = "KacyCatanzaro",
                    ServedInOniwaban = false,
                    DateOfBirth      = new DateTime(1990, 1, 14),
                    ClanId           = 1
                };

                var muscles = new NinjaEquipment()
                {
                    Name = "Muscles",
                    Type = EquipmentType.Tool
                };

                var spunk = new NinjaEquipment()
                {
                    Name = "Spunk",
                    Type = EquipmentType.Weapon
                };

                //
                // Equipments is not add explicitly on the context
                //   It works.
                //
                // The operation is done in one transaction with one connection.
                //
                // The NinjaEquipment model don't contain a FK for a Ninja.
                //   A FK is create to maintain the relation with from the models.
                //     Ninja_Id
                //     [Model]_[ModelPK]
                //
                context.Ninjas.Add(ninja);
                ninja.EquipmentOwned.Add(muscles);
                ninja.EquipmentOwned.Add(spunk);
                context.SaveChanges();
            }
        }
Пример #19
0
        private static void InsertNinja()
        {
            //instantiate ninjacontext object
            var ninja = new Ninja
            {
                Name             = "ObiEight",
                ServedInOniwaban = true,
                DateOfBirth      = new DateTime(1944, 7, 2),
                ClanId           = 1
            };

            //use EF to insert data to DB
            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;
                // add lets to insert nly one
                context.Ninjas.Add(ninja);
                context.SaveChanges();
            }
        }
Пример #20
0
        private static void InsertNinja()
        {
            var ninjas = new List <Ninja>();

            for (int i = 21; i < 30; i++)
            {
                var ninja = new Ninja
                {
                    Name             = "SalihSan" + i,
                    ServedInOniwaban = (i % 2 == 0),
                    DateOfBirth      = new DateTime(1978, 11, i),
                    ClanId           = (i % 2 == 0) ? 1 : 2
                };

                var equipment = new NinjaEquipment()
                {
                    Name = "equipment " + i,
                    Type = EquipmentType.Weapon
                };

                ninja.EquipmentOwned.Add(equipment);

                equipment = new NinjaEquipment()
                {
                    Name = "equipmentTool " + i,
                    Type = EquipmentType.Tool
                };

                ninja.EquipmentOwned.Add(equipment);

                ninjas.Add(ninja);
            }


            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;
                context.Ninjas.AddRange(ninjas);
                context.SaveChanges();
            }
        }
Пример #21
0
        private static void InsertNinja()
        {
            //Instantiate new ninja object and hydrate
            var ninja = new Ninja
            {
                Name             = "DerekSan",
                ServedInOniwaban = false,
                DateOfBirth      = new DateTime(1990, 3, 2),
                ClanId           = 1
            };

            //connect to out database context in a using statment to handle dispose
            using (var context = new NinjaContext())
            {
                //Log via console what the database is doing
                context.Database.Log = Console.WriteLine;
                //(Use .Add to insert a single object)Adding our hydrated object to out DBContext declaring what table to add it to
                //Format: CONTEXT.TABLE.COMMAND(PARAM)
                context.Ninjas.Add(ninja);
                //Tell context to save our changes
                context.SaveChanges();
            }
        }
Пример #22
0
        private static void InsertNinjaWithEquipment()
        {
            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;

                var ninja = new Ninja()
                {
                    Name = "Raphel",
                    ServiceInOniwaban = false,
                    DateOfBirth       = new DateTime(1990, 1, 1),
                    ClanId            = 1
                };
                var sai = new NinjaEquipment
                {
                    Name = "Sai",
                    Type = EquipmentType.Weapon
                };
                context.Ninjas.Add(ninja);
                ninja.EquipmentOwned.Add(sai);
                context.SaveChanges();
            }
        }
Пример #23
0
        //private static void DeleteNinjaViaStoredProcedure()
        //{
        //    var keyval = 3;
        //    using (var context = new NinjaContext())
        //    {
        //        context.Database.Log = Console.WriteLine;
        //        context.Database.ExecuteSqlCommand(
        //            "exec DeleteNinjaViaId {0}", keyval);
        //    }
        //}

        private static void InsertNinjaWithEquipment()
        {
            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;

                var ninja = new Ninja
                {
                    Name             = "Kacy Catanzaro",
                    ServedInOniwaban = false,
                    DateOfBirth      = new DateTime(1990, 1, 14),
                    ClanId           = 1
                };
                var muscles = new NinjaEquipment
                {
                    Name = "Muscles",
                    Type = EquipmentType.Tool,
                };
                var spunk = new NinjaEquipment
                {
                    Name = "Spunk",
                    Type = EquipmentType.Weapon
                };

                //LD here we add some object "NinjaEquipment" to the "EquipmentOwned" of this specific ninja
                //LD TO DON'T HAVE ERRORS HERE I HAVE TO INITIALIZE "EquipmentOwned" in the class ninja
                //public Ninja()
                //{
                //    EquipmentOwned = new List<NinjaEquipment>();
                //}
                ninja.EquipmentOwned.Add(muscles);
                ninja.EquipmentOwned.Add(spunk);

                context.Ninjas.Add(ninja);
                context.SaveChanges();
            }
        }
Пример #24
0
        public static void Main(string[] args)
        {
            // Human human1 = new Human("Daniel");
            // Human human2 = new Human("Daniela", 500000, 100000,100,1);
            // System.Console.WriteLine(human1);
            // System.Console.WriteLine(human2);
            // System.Console.WriteLine("_________________________________________________");
            // Ninja ninja1 = new Ninja("Tom");
            // Ninja ninja2 = new Ninja("Rick");
            // Ninja ninja3 = new Ninja("Bill");
            // Ninja ninja4 = new Ninja("Serina");
            // ninja1.how_many();
            // System.Console.WriteLine("_________________________________________________");
            // Samurai samurai1 = new Samurai("MADGUY");
            // Samurai samurai2 = new Samurai("MADGUYFRIEND");
            // System.Console.WriteLine("_________________________________________________");
            // Wizard wizard1 = new Wizard("Chris");
            // Wizard wizard2 = new Wizard("NotChris");
            // System.Console.WriteLine(wizard1.ToString());
            // wizard1.fireball(human1);
            // wizard1.fireball(human2);
            // wizard1.fireball(ninja1);
            // wizard1.heal();

            // samurai1.death_blow(wizard2);
            // samurai1.meditate();

            // MAKE A GAME LOOP
            // WHILE GAMEGOING && HUMAN'S EXIST AND ENEMIES EXIST

            // INSIDE THE LOOK AS FOR INPUT FROM THE USER OF WHAT MOVE TO USE
            // WHEN ITS THE ENEMIES TURN RANDOMLY ATTACK
            // RANDOM ATTACK
            // MAKE MORE ATTACKS AND BASED ON THE NUMBER PICK THE ATTACK.
            // SPIDER - ATTACK() SILKATTACK() - dexterity * random  CRAWL() health * intellegence
            // ZOMBIE - ATTACK() biteATTACK() SCRATCH()
            // WHILE(GAMEGOING && (zombie.health > 0 || spider.health > 0 || spider2.health > 0) && (ninja.health > 0 || samurai.health > 0 || wizard.health > 0))
            // TYPE(PLAY, END, RESTART, VIEWSTATS)
            // WHEN NO MORE ENEMIES OR HUMANS END LOOP ANNOUSE THE WINNER (WHO IS STILL ALIVE)
            // RETURN THE INSTANCES TO SEE HOW MANY EXIST
            //

            Spider spider  = new Spider("Spider");
            Spider spider2 = new Spider("Spider 2");
            Zombie zombie  = new Zombie("Zombie");

            Ninja   ninja   = new Ninja("Larry the Ninja");
            Samurai samurai = new Samurai("Jerry the Samurai");
            Wizard  wizard  = new Wizard("Gary the Wizard");


            spider.silkAttack(ninja);
            spider.silkAttack(samurai);
            spider.silkAttack(wizard);
            zombie.biteAttack(wizard);
            spider2.silkAttack(wizard);

            ninja.attack(spider);
            samurai.attack(spider);
            wizard.fireball(zombie);
        }