private static void InsertNinja()
 {
     var ninja = new Ninja()
     {
         Name = "Leonardo",
         ServedInOniwaban = true,
         DateOfBirth = new DateTime(1972, 8, 11),
         ClanId = 1,
     };
     using (var context = new NinjaContext())
     {
         context.Database.Log = Console.WriteLine;
         context.Ningas.Add(ninja);
         context.SaveChanges();
     }
 }
        private static void InsertRelatedData()
        {
            var ninja = new Ninja()
            {
                Name = "Kacy Katanzaro",
                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
            };

            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;
                context.Ningas.Add(ninja);
                ninja.EquipmentOwned.Add(muscles);
                ninja.EquipmentOwned.Add(spunk);
                context.SaveChanges();
            }
        }
 private void btnNewNinja_Click(object sender, RoutedEventArgs e)
 {
     if (ShouldRefresh)
     {
         _currentNinja = _repo.NewNinja();
         RefreshNinja();
     }
 }
 private void ninjaListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     bool continueProcess;
     if (_isLoading)
     {
         continueProcess = true;
     }
     else
     {
         continueProcess = ShouldRefresh;
     }
     if (!continueProcess) return;
     if (ninjaListBox.SelectedItem != null)
     {
         _currentNinja = _repo.GetNinjaWithEquipment(
             ((int) ninjaListBox.SelectedValue)
             );
     }
     RefreshNinja();
     _isNinjaListChanging = false;
 }
        public static void NewDbWithSeed()
        {
            Database.SetInitializer(new DropCreateDatabaseAlways<NinjaContext>());
            using (var context = new NinjaContext())
            {
                if (context.Ningas.Any())
                {
                    return;
                }
                var vtClan = context.Clans.Add(new Clan { ClanName = "Vermont Clan" });
                var turtleClan = context.Clans.Add(new Clan { ClanName = "Turtles" });
                var amClan = context.Clans.Add(new Clan { ClanName = "American Ninja Warriors" });

                var j = new Ninja
                {
                    Name = "JulieSan",
                    ServedInOniwaban = false,
                    DateOfBirth = new DateTime(1980, 1, 1),
                    Clan = vtClan

                };
                var s = new Ninja
                {
                    Name = "SampsonSan",
                    ServedInOniwaban = false,
                    DateOfBirth = new DateTime(2008, 1, 28),
                    ClanId = 1

                };
                var l = new Ninja
                {
                    Name = "Leonardo",
                    ServedInOniwaban = false,
                    DateOfBirth = new DateTime(1984, 1, 1),
                    Clan = turtleClan
                };
                var r = new Ninja
                {
                    Name = "Raphael",
                    ServedInOniwaban = false,
                    DateOfBirth = new DateTime(1985, 1, 1),
                    Clan = turtleClan
                };
                context.Ningas.AddRange(new List<Ninja> { j, s, l, r });
                var ninjaKC = new Ninja
                {
                    Name = "Kacy Catanzaro",
                    ServedInOniwaban = false,
                    DateOfBirth = new DateTime(1990, 1, 14),
                    Clan = amClan
                };
                var muscles = new NinjaEquipment
                {
                    Name = "Muscles",
                    Type = EquipmentType.Tool,

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

                ninjaKC.EquipmentOwned.Add(muscles);
                ninjaKC.EquipmentOwned.Add(spunk);
                context.Ningas.Add(ninjaKC);

                context.SaveChanges();
                context.Database.ExecuteSqlCommand(
                  @"CREATE PROCEDURE GetOldNinjas
                    AS  SELECT * FROM Ninjas WHERE DateOfBirth<='1/1/1980'");

                context.Database.ExecuteSqlCommand(
                   @"CREATE PROCEDURE DeleteNinjaViaId
                     @Id int
                     AS
                     DELETE from Ninjas Where Id = @id
                     RETURN @@rowcount");
            }
        }
 public Ninja NewNinja()
 {
     var ninja = new Ninja();
     _context.Ningas.Add(ninja);
     return ninja;
 }
 public void DeleteCurrentNinja(Ninja ninja)
 {
     _context.Ningas.Remove(ninja);
     Save();
 }