예제 #1
0
        private static void InsertMultipleNinjas()
        {
            var ninja1 = new NinjaDomain.Classes.Ninja()
            {
                Name             = "Raphael",
                ServedInOniwaban = false,
                DateOfBirth      = new DateTime(1986, 06, 20),
                ClanId           = 1
            };
            var ninja2 = new NinjaDomain.Classes.Ninja()
            {
                Name             = "Donatelo",
                ServedInOniwaban = false,
                DateOfBirth      = new DateTime(1986, 06, 20),
                ClanId           = 1
            };

            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;
                context.Ninjas.AddRange(new List <NinjaDomain.Classes.Ninja>()
                {
                    ninja1, ninja2
                });
                context.SaveChanges();
            }
        }
예제 #2
0
        private static void InsertNinjaWithEquipment()
        {
            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;

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

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

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

                context.Ninjas.Add(ninja);
                ninja.EquipmentOwned.Add(muscles);
                ninja.EquipmentOwned.Add(spunk);
                context.SaveChanges();

            }
        }
예제 #3
0
        private static void InsertMultipleNinjas()
        {
            var ninja2 = new Ninja
            {
                Name = "SampsonSan",
                ServedInOniwaban = false,
                DateOfBirth = new DateTime(2008, 1, 28),
                ClanId = 1
            };

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

            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;
                context.Ninjas.AddRange(new List<Ninja> { ninja2, ninjas22});
                context.SaveChanges();
            }
        }
예제 #4
0
        private static void InsertMultipleNinjas()
        {
            var ninja1 = new Ninja
            {
                Name = "Leonardo",
                ServedInOniwaban = false,
                DateOfBirth = new DateTime(1984, 10, 02),
                ClanId = 1
            };

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

            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;

                // Same INSERT as in InsertNinja, but doen multiple times in one db call
                context.Ninjas.AddRange(new List<Ninja> { ninja1, ninja2 });
                context.SaveChanges();
            }
        }
예제 #5
0
 private static void InsertNinjaWithEquipment()
 {
     using (var context = new NinjaContext())
     {
         context.Database.Log = Console.WriteLine;
         var ninja = new NinjaDomain.Classes.Ninja
         {
             Name             = "Kacy Cantazaro",
             ServedInOniwaban = false,
             DateOfBirth      = new DateTime(1986, 06, 20),
             ClanId           = 1
         };
         var muscles = new NinjaEquipment
         {
             Name = "Muscles",
             Type = EquipmentType.Tool
         };
         var spunk = new NinjaEquipment
         {
             Name = "Spunk",
             Type = EquipmentType.Weapon
         };
         context.Ninjas.Add(ninja);
         ninja.EquipmentOwned.Add(muscles);
         ninja.EquipmentOwned.Add(spunk);
         context.SaveChanges();
     }
 }
예제 #6
0
 private void btnNewNinja_Click(object sender, RoutedEventArgs e)
 {
     if (ShouldRefresh)
       {
     _currentNinja = _repo.NewNinja();
     RefreshNinja();
       }
 }
예제 #7
0
        private static void InsertNinjas()
        {
            var ninja = new NinjaDomain.Classes.Ninja()
            {
                Name             = "Junar",
                ServedInOniwaban = false,
                DateOfBirth      = new DateTime(1986, 06, 20),
                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())
            {
                context.Database.Log = Console.WriteLine;
                context.Ninjas.Add(ninja);
                context.SaveChanges();
            }
        }
예제 #9
0
        //
        //   INSERT
        //
        private static void InsertNinja()
        {
            var ninja = new Ninja
            {
                Name = "TerriSan", ServedInOniwaban = false, DateOfBirth = new DateTime(1980,1,1), ClanId = 5
            };

            var ninja2 = new Ninja
            {
                Name = "JulieLerman",  ServedInOniwaban = false, DateOfBirth = new DateTime(1970, 1, 1), ClanId = 5
            };

            //now lets use EF to insert this object
            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;
                //context.Ninjas.Add(ninja);
                //context.Ninjas.Add(ninja2);
                context.Ninjas.AddRange(new List<Ninja> { ninja, ninja2 });
                context.SaveChanges();
            }
        }
예제 #10
0
 private static void InsertNinja()
 {
     var n = new Ninja
     {
         Name = "ChrisSan",
         ServedInOniwaban = false,
         DatOfBirth = new DateTime(1946, 4, 4),
         ClanId = 1
     };
     var n2 = new Ninja
     {
         Name = "BijanSan",
         ServedInOniwaban = false,
         DatOfBirth = new DateTime(1993, 4, 4),
         ClanId = 1
     };
     using (var context = new NinjaContext())
     {
         context.Database.Log = Console.WriteLine;
         context.Ninjas.Add(n);
         context.Ninjas.Add(n2);
         context.SaveChanges();
     }
 }
 public void SaveNewNinja(Ninja ninja)
 {
     using (var context = new NinjaContext()) {
     context.Ninjas.Add(ninja);
     context.SaveChanges();
       }
 }
 public void SaveUpdatedNinja(Ninja ninja)
 {
     using (var context = new NinjaContext()) {
     context.Entry(ninja).State = EntityState.Modified;
     context.SaveChanges();
       }
 }
예제 #13
0
        private static void InsertNinja()
        {
            var ninja = new Ninja
            {
                Name = "PenelopeSan",
                ServedInOniwaban = false,
                DateOfBirth = new DateTime(2015, 01, 08),
                ClanId = 1
            };

            using (var context = new NinjaContext())
            {
                // point the database log function to Console, so we can see the output
                context.Database.Log = Console.WriteLine;

                // Calls sql INSERT function - INSERT [dbo].[Ninjas]([Name], [ServedInOniwaban], [ClanId], [DateOfBirth])
                context.Ninjas.Add(ninja);

                // This must be called, or changes to the context will not be applied to the actual db
                context.SaveChanges();
            }
        }
예제 #14
0
        private static void InsertNinjaWithEquipment()
        {
            using (var context = new NinjaContext())
            {
                context.Database.Log = Console.WriteLine;
                var ninja = new Ninja
                {
                  Name = "Kacy Catanzaro" , ServedInOniwaban = true, DateOfBirth = new DateTime (1975,7,2), ClanId = 1
                };
                var muscles = new NinjaEquipment { Name = "Muscles", Type = EquipmentType.Blade };
                var spunk = new NinjaEquipment { Name = "Spunk", Type = EquipmentType.Sword };

                context.Ninjas.Add(ninja);
                ninja.EquipmentOwned.Add(muscles);
                ninja.EquipmentOwned.Add(spunk);
                context.SaveChanges();
            }
        }
예제 #15
0
        // used to prepare db for part 4
        private static void ReseedDatabase()
        {
            Database.SetInitializer(new DropCreateDatabaseAlways<NinjaContext>());
            using (var context = new NinjaContext())
            {
                context.Clans.Add(new Clan { ClanName = "Vermont Clan" });
                var j = new Ninja
                {
                    Name = "JulieSan",
                    ServedInOniwaban = false,
                    DateOfBirth = new DateTime(1980, 1, 1),
                    ClanId = 1

                };
                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),
                    ClanId = 1
                };
                var r = new Ninja
                {
                    Name = "Raphael",
                    ServedInOniwaban = false,
                    DateOfBirth = new DateTime(1985, 1, 1),
                    ClanId = 1
                };
                context.Ninjas.AddRange(new List<Ninja> { j, s, l, r });
                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");
            }
        }
예제 #16
0
 public void DeleteCurrentNinja(Ninja ninja)
 {
     _context.Ninjas.Remove(ninja);
     Save();
 }
예제 #17
0
 private void ninjaListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     bool continueProcess;
       if (_isLoading) {
     continueProcess = true;
       }
       else {
     continueProcess = ShouldRefresh;
       }
       if (!continueProcess) return;
       _currentNinja = _repo.GetNinjaWithEquipment(
     ((int)ninjaListBox.SelectedValue)
     );
       RefreshNinja();
       _isNinjaListChanging = false;
 }
예제 #18
0
 public Ninja NewNinja()
 {
     var ninja = new Ninja();
     _context.Ninjas.Add(ninja);
     return ninja;
 }
예제 #19
0
        // clears the db and reseeds with new data
        public static void NewDbWithSeed()
        {
            Database.SetInitializer(new DropCreateDatabaseAlways<NinjaContext>());

            using (var context = new NinjaContext())
            {
                if (context.Ninjas.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.Ninjas.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.Ninjas.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");
            }
        }
예제 #20
0
 public Ninja NewNinja()
 {
     var n = new Ninja();
     _ninjas.Add(n);
     return n;
 }