示例#1
0
        static void Main(string[] args) {
            IRepository repo = new NHRepository();
            ContactenDBInitializer.Seed(repo);

            Contact c = new Contact { Name = "Wout Lambreghts", Address = new Address {
                StreetAndNumber = "Lepelstraat 41",
                ZipCode = 2340,
                City = "Vlimmeren"},
                Gender = Gender.Male,
                BirthDay = new DateTime(1995, 06, 18),
                Phone = "033091289",
                Mobile = "0474743473",
                Blocked = false };
            //Wegschrijven naar database
            repo.CreateContact(c);
            Console.WriteLine("Contact has been succesfully saved in the database.");

            //Lezen van database
            List<Contact> contacten = repo.ReadAllContacts().ToList();
            Console.WriteLine("All contacts have been succesfully read from the database.");
            contacten.ForEach(con => Console.WriteLine(con.ToString()));

            
            Console.ReadKey();
        }
示例#2
0
 public void UpdateContact(Contact contactToUpdate) {
     using (ISession sessie = openSessie()) {
         using (ITransaction transactie = sessie.BeginTransaction()) {
             sessie.SaveOrUpdate(contactToUpdate);
             transactie.Commit();
         }
     }
 }
        public static void Seed(IRepository repo) {
            //base.Seed(context);

            // Dummy data
            // Categories
            Category cat1 = new Category() { Description = "Family" };
            Category cat2 = new Category() { Description = "Friends" };
            Category cat3 = new Category() { Description = "School" };
            Category cat4 = new Category() { Description = "Sports" };
            /*
                repo.(cat1);
                context.Categories.Add(cat2);
                context.Categories.Add(cat3);
                context.Categories.Add(cat4);

                context.SaveChanges();
                */
            // Contacts
            Contact c1 = new Contact();
            c1.Name = "Verstraeten Micheline";
            c1.BirthDay = new DateTime(1978, 8, 30);
            c1.Address = new Address();
            c1.Address.StreetAndNumber = "Antwerpsestraat 20";
            c1.Address.ZipCode = 2000;
            c1.Address.City = "Antwerpen";
            c1.Gender = Gender.Female;
            c1.Blocked = false;
            c1.Phone = "03/123.45.67";
            c1.Mobile = "0495/11.22.33";
            c1.Categories = new HashSet<Category>();
            c1.Categories.Add(cat1);

            Contact c2 = new Contact();
            c2.Name = "Bogaerts Sven";
            c2.BirthDay = new DateTime(1975, 4, 12);
            c2.Address = new Address();
            c2.Address.StreetAndNumber = "Brusselsestraat 10";
            c2.Address.ZipCode = 1000;
            c2.Address.City = "Brussel";
            c2.Gender = Gender.Male;
            c2.Blocked = false;
            c2.Mobile = "0478/12.34.56";
            c2.Categories = new HashSet<Category>();
            c2.Categories.Add(cat1);
            c2.Categories.Add(cat3);
            c2.Categories.Add(cat4);

            Contact c3 = new Contact();
            c3.Name = "Vlaeminckx Dieter";
            c3.BirthDay = new DateTime(1980, 12, 8);
            c3.Address = new Address();
            c3.Address.StreetAndNumber = "Gentsestraat 95";
            c3.Address.ZipCode = 9000;
            c3.Address.City = "Gent";
            c3.Gender = Gender.Male;
            c3.Blocked = true;
            c3.Mobile = "0479/98.76.54";
            c3.Categories = new HashSet<Category>();
            c3.Categories.Add(cat1);
            c3.Categories.Add(cat4);

            Contact c4 = new Contact();
            c4.Name = "Vlaeminckx Jef";
            c4.BirthDay = new DateTime(1952, 10, 21);
            c4.Address = new Address();
            c4.Address.StreetAndNumber = "Gentselaan 9";
            c4.Address.ZipCode = 9000;
            c4.Address.City = "Gent";
            c4.Gender = Gender.Male;
            c4.Blocked = true;
            c4.Phone = "09/99.88.77";
            c4.Categories = new HashSet<Category>();
            c4.Categories.Add(cat1);

            repo.CreateContact(c1);
            repo.CreateContact(c2);
            repo.CreateContact(c3);
            repo.CreateContact(c4);

            /*
                context.Contacts.Add(c1);
                context.Contacts.Add(c2);
                context.Contacts.Add(c3);
                context.Contacts.Add(c4);

                context.SaveChanges();
                */
        }
示例#4
0
 public void CreateContact(Contact contactToInsert) {
     UpdateContact(contactToInsert);
 }