private static void InsertMultipleWarriors()
        {
            var warrior1 = new Warrior
            {
                Name            = "Eric Sanderson",
                ServedInKingdom = true,
                DateOfBirth     = new DateTime(1968, 2, 2),
                BloodId         = 1
            };
            var warrior2 = new Warrior
            {
                Name            = "Christopher Crusit",
                ServedInKingdom = true,
                DateOfBirth     = new DateTime(1962, 3, 3),
                BloodId         = 1
            };

            using (var context = new WarriorContext())
            {
                context.Database.Log = Console.WriteLine;
                context.Warriors.AddRange(new List <Warrior> {
                    warrior1, warrior2
                });
                context.SaveChanges();
            }
        }
        private static void InserWarriorWithEquipment()
        {
            using (var context = new WarriorContext())
            {
                context.Database.Log = Console.WriteLine;

                var warrior = new Warrior
                {
                    Name            = "Robert Istern",
                    ServedInKingdom = true,
                    DateOfBirth     = new DateTime(1991, 3, 4),
                    BloodId         = 1
                };
                var bigSword = new WarriorEquipment
                {
                    Name = "Crystal Sword",
                    Type = EquipmentType.Weapon
                };
                var chainArmor = new WarriorEquipment
                {
                    Name = "Chain Armor",
                    Type = EquipmentType.Outwear
                };
                context.Warriors.Add(warrior);
                warrior.EquipmentOwned.Add(bigSword);
                warrior.EquipmentOwned.Add(chainArmor);
                context.SaveChanges();
            }
        }
 private static void QueryAndUpdateWarrior()
 {
     using (var context = new WarriorContext())
     {
         context.Database.Log = Console.WriteLine;
         var warrior = context.Warriors.FirstOrDefault();
         warrior.ServedInKingdom = (!warrior.ServedInKingdom);
         context.SaveChanges();
     }
 }
        public WarriorController(WarriorContext context)
        {
            _context = context;

            if (_context.Warriors.Count() == 0)
            {
                // Create new warrior item if collection is empty
                _context.Warriors.Add(new Warrior {
                    Name = "Warrior1", Health = 500, Attack = 250, Defense = 250
                });
                _context.Warriors.Add(new Warrior {
                    Name = "Warrior2", Health = 500, Attack = 250, Defense = 250
                });
                _context.SaveChanges();
            }
        }
        private static void InsertWarrior()
        {
            var wojownik = new Warrior
            {
                Name            = "TomRent",
                ServedInKingdom = false,
                DateOfBirth     = new DateTime(1998, 1, 1),
                BloodId         = 1
            };

            using (var context = new WarriorContext())
            {
                context.Database.Log = Console.WriteLine;
                context.Warriors.Add(wojownik);
                context.SaveChanges();
            }
        }
        private static void QueryAndUpdateWarriorDisconnected()
        {
            Warrior warrior;

            using (var context = new WarriorContext())
            {
                context.Database.Log = Console.WriteLine;
                warrior = context.Warriors.FirstOrDefault();
            }
            warrior.ServedInKingdom = (!warrior.ServedInKingdom);

            using (var context = new WarriorContext())
            {
                context.Database.Log = Console.WriteLine;
                context.Warriors.Add(warrior);
                context.Entry(warrior).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
        private static void DeleteWarrior()
        {
            Warrior warrior;

            using (var context = new WarriorContext())
            {
                context.Database.Log = Console.WriteLine;
                warrior = context.Warriors.FirstOrDefault();
                //context.Warriors.Remove(warrior);
                //context.SaveChanges();
            }
            using (var context = new WarriorContext())
            {
                context.Database.Log = Console.WriteLine;
                //context.Warriors.Attach(warrior);
                //context.Warriors.Remove(warrior);
                context.Entry(warrior).State = EntityState.Deleted;
                context.SaveChanges();
            }
        }