예제 #1
0
        public static void Initialize(OutlookContext context)
        {
            var students = new User[]
            {
                new User {
                    Name = "Jan", Surname = "Kowalski", EmailAddress = "*****@*****.**", Role = 0
                },
                new User {
                    Name = "Adam", Surname = "Nowak", EmailAddress = "*****@*****.**", Role = 0
                },
            };
            var groups = new Group[]
            {
                new Group {
                    OwnerId = 1, GroupName = "Grupa A"
                },
                new Group {
                    OwnerId = 2, GroupName = "Grupa B"
                },
            };
            var groupMembers = new GroupMember[]
            {
                new GroupMember {
                    UserId = 1, GroupId = 2
                },
                new GroupMember {
                    UserId = 2, GroupId = 1
                }
            };


            if (Recreate)
            {
                context.Database.EnsureDeleted();
            }
            context.Database.EnsureCreated();
            if (!context.Users.Any())
            {
                foreach (User s in students)
                {
                    context.Users.Add(s);
                }
                context.SaveChanges();
            }
            if (!context.Groups.Any())
            {
                foreach (Group s in groups)
                {
                    context.Groups.Add(s);
                }
                context.SaveChanges();
            }
            if (!context.GroupMembers.Any())
            {
                foreach (GroupMember s in groupMembers)
                {
                    context.GroupMembers.Add(s);
                }
                context.SaveChanges();
            }
        }
예제 #2
0
 public static void Initialize(OutlookContext context)
 {
     if (Recreate)
     {
         context.GroupMembers.RemoveRange(context.GroupMembers);
         context.MessageReceivers.RemoveRange(context.MessageReceivers);
         context.Users.RemoveRange(context.Users);
         context.Groups.RemoveRange(context.Groups);
         context.Messages.RemoveRange(context.Messages);
         context.SaveChanges();
     }
     //var students = new User[]
     //    {
     //        new User{Name="Jan",Surname="Kowalski",EmailAddress="*****@*****.**",Role=0},
     //        new User{Name="Adam",Surname="Nowak",EmailAddress="*****@*****.**",Role=0},
     //        new User{Name="Marcin",Surname="Nowak",EmailAddress="*****@*****.**",Role=0},
     //        new User{Name="Daria",Surname="Nowak",EmailAddress="*****@*****.**",Role=0},
     //        new User{Name="Tomasz",Surname="Nowak",EmailAddress="*****@*****.**",Role=0},
     //        new User{Name="Anna",Surname="Kowalska",EmailAddress="*****@*****.**",Role=0},
     //        new User{Name="Przemysław",Surname="Nowak",EmailAddress="*****@*****.**",Role=0},
     //        new User{Name="Henryk",Surname="Nowak",EmailAddress="*****@*****.**",Role=0},
     //        new User{Name="Wiele",Surname="wierszy",EmailAddress="*****@*****.**",Role=0},
     //        new User{Name="Do",Surname="Testowania",EmailAddress="*****@*****.**",Role=0},
     //        new User{Name="Scrollowania",Surname="Dlugiej",EmailAddress="*****@*****.**",Role=0},
     //        new User{Name="Listy",Surname="Kontaktow",EmailAddress="*****@*****.**",Role=0},
     //    };
     //var groups = new Group[]
     //    {
     //        new Group{OwnerId=1, GroupName="Grupa A"},
     //        new Group{OwnerId=2, GroupName="Grupa B"},
     //    };
     //var groupMembers = new GroupMember[]
     //    {
     //        new GroupMember{UserId=1, GroupId=2},
     //        new GroupMember{UserId=2, GroupId=1}
     //    };
     //if (!context.Users.Any())
     //{
     //    foreach (User s in students)
     //    {
     //        context.Users.Add(s);
     //    }
     //    context.SaveChanges();
     //}
     //if (!context.Groups.Any())
     //{
     //    foreach (Group s in groups)
     //    {
     //        context.Groups.Add(s);
     //    }
     //    context.SaveChanges();
     //}
     //if (!context.GroupMembers.Any())
     //{
     //    foreach (GroupMember s in groupMembers)
     //    {
     //        context.GroupMembers.Add(s);
     //    }
     //    context.SaveChanges();
     //}
 }