Пример #1
0
        private static async Task RunMyChildDemo(IServiceProvider servProv)
        {
            /* Create seed data for the In Memory Database.  NOT for Production type of code */
            EfPlaygroundDbContext context = servProv.GetRequiredService <EfPlaygroundDbContext>();
            ////MyChildDataGenerator.Initialize(servProv);

            IChildDemos demo = servProv.GetService <IChildDemos>();
            await demo.PerformBasicCrudDemo();
        }
Пример #2
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new EfPlaygroundDbContext(
                       serviceProvider.GetRequiredService <DbContextOptions <EfPlaygroundDbContext> >(), serviceProvider.GetRequiredService <Microsoft.Extensions.Logging.ILoggerFactory>()))
            {
                // Look for any board games already in database.
                if (context.BoardGames.Any())
                {
                    return;   // Database has been seeded
                }

                context.BoardGames.AddRange(
                    new BoardGameEntity
                {
                    BoardGameKey      = 1,
                    Title             = "Candy Land",
                    PublishingCompany = "Hasbro",
                    MinPlayers        = 2,
                    MaxPlayers        = 4
                },
                    new BoardGameEntity
                {
                    BoardGameKey      = 2,
                    Title             = "Sorry!",
                    PublishingCompany = "Hasbro",
                    MinPlayers        = 2,
                    MaxPlayers        = 4
                },
                    new BoardGameEntity
                {
                    BoardGameKey      = 3,
                    Title             = "Monopoly",
                    PublishingCompany = "Parker Brothers",
                    MinPlayers        = 2,
                    MaxPlayers        = 5
                },
                    new BoardGameEntity
                {
                    BoardGameKey      = 4,
                    Title             = "King of Tokyo",
                    PublishingCompany = "Iello",
                    MinPlayers        = 2,
                    MaxPlayers        = 6
                },
                    new BoardGameEntity
                {
                    BoardGameKey      = 5,
                    Title             = "Guillotine",
                    PublishingCompany = "Avalon",
                    MinPlayers        = 2,
                    MaxPlayers        = 6
                });

                context.SaveChanges();
            }
        }
Пример #3
0
        public MyChildEntityFrameworkDomainDataLayer(ILoggerFactory loggerFactory, EfPlaygroundDbContext context)
        {
            if (null == loggerFactory)
            {
                throw new ArgumentNullException(ErrorMessageILoggerFactoryWrapperIsNull, (Exception)null);
            }

            this.logger          = loggerFactory.CreateLogger <MyChildEntityFrameworkDomainDataLayer>();
            this.entityDbContext = context ?? throw new ArgumentNullException(ErrorMessageBoardGamesDbContextIsNull, (Exception)null);
        }
Пример #4
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new EfPlaygroundDbContext(
                       serviceProvider.GetRequiredService <DbContextOptions <EfPlaygroundDbContext> >(), serviceProvider.GetRequiredService <Microsoft.Extensions.Logging.ILoggerFactory>()))
            {
                // Look for any board games already in database.
                if (context.VerticalConfigurationCategories.Any())
                {
                    return;   // Database has been seeded
                }

                context.VerticalConfigurationCategories.AddRange(
                    new VerticalConfigurationCategoryEntity
                {
                    VerticalConfigurationCategoryKey  = 101,
                    VerticalConfigurationCategoryName = "General Settings",
                    UpdateDateUtc = DateTimeOffset.Now,
                    VerticalConfigurationEntryEntities = new List <VerticalConfigurationEntryEntity>
                    {
                        new VerticalConfigurationEntryEntity()
                        {
                            VerticalConfigurationEntryKey = 10101, ParentVerticalConfigurationCategoryKey = 101, KeyName = "MinimumBirthDate", Value = "01/01/1890", UpdateDateUtc = DateTimeOffset.Now
                        },
                        new VerticalConfigurationEntryEntity()
                        {
                            VerticalConfigurationEntryKey = 10102, ParentVerticalConfigurationCategoryKey = 101, KeyName = "MinThreshold", Value = "-100", UpdateDateUtc = DateTimeOffset.Now
                        },
                        new VerticalConfigurationEntryEntity()
                        {
                            VerticalConfigurationEntryKey = 10103, ParentVerticalConfigurationCategoryKey = 101, KeyName = "MaxThreshold", Value = "100", UpdateDateUtc = DateTimeOffset.Now
                        }
                    }
                },
                    new VerticalConfigurationCategoryEntity
                {
                    VerticalConfigurationCategoryKey  = 201,
                    VerticalConfigurationCategoryName = "ZipCode Settings",
                    UpdateDateUtc = DateTimeOffset.Now,
                    VerticalConfigurationMultiEntries = new List <VerticalConfigurationMultiEntryEntity>
                    {
                        new VerticalConfigurationMultiEntryEntity()
                        {
                            VerticalConfigurationMultiEntryKey = 20101, ParentVerticalConfigurationCategoryKey = 201, Value = "11111", Sequence = 1, UpdateDateUtc = DateTimeOffset.Now
                        },
                        new VerticalConfigurationMultiEntryEntity()
                        {
                            VerticalConfigurationMultiEntryKey = 20102, ParentVerticalConfigurationCategoryKey = 201, Value = "22222", Sequence = 2, UpdateDateUtc = DateTimeOffset.Now
                        },
                        new VerticalConfigurationMultiEntryEntity()
                        {
                            VerticalConfigurationMultiEntryKey = 20109, ParentVerticalConfigurationCategoryKey = 201, Value = "99999", Sequence = 3, UpdateDateUtc = DateTimeOffset.Now
                        }
                    }
                },
                    new VerticalConfigurationCategoryEntity
                {
                    VerticalConfigurationCategoryKey  = 301,
                    VerticalConfigurationCategoryName = "Favorite Colors",
                    UpdateDateUtc = DateTimeOffset.Now,
                    VerticalConfigurationMultiEntries = new List <VerticalConfigurationMultiEntryEntity>
                    {
                        new VerticalConfigurationMultiEntryEntity()
                        {
                            VerticalConfigurationMultiEntryKey = 30101, ParentVerticalConfigurationCategoryKey = 301, Value = "Red", Sequence = 1, UpdateDateUtc = DateTimeOffset.Now
                        },
                        new VerticalConfigurationMultiEntryEntity()
                        {
                            VerticalConfigurationMultiEntryKey = 30102, ParentVerticalConfigurationCategoryKey = 301, Value = "Yellow", Sequence = 2, UpdateDateUtc = DateTimeOffset.Now
                        },
                        new VerticalConfigurationMultiEntryEntity()
                        {
                            VerticalConfigurationMultiEntryKey = 30103, ParentVerticalConfigurationCategoryKey = 301, Value = "Black", Sequence = 3, UpdateDateUtc = DateTimeOffset.Now
                        },
                        new VerticalConfigurationMultiEntryEntity()
                        {
                            VerticalConfigurationMultiEntryKey = 30104, ParentVerticalConfigurationCategoryKey = 301, Value = "White", Sequence = 3, UpdateDateUtc = DateTimeOffset.Now
                        }
                    }
                });

                context.SaveChanges();
            }
        }
Пример #5
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new EfPlaygroundDbContext(
                       serviceProvider.GetRequiredService <DbContextOptions <EfPlaygroundDbContext> >(), serviceProvider.GetRequiredService <Microsoft.Extensions.Logging.ILoggerFactory>()))
            {
                if (context.MyParents.Any())
                {
                    return;   // Database has been seeded
                }

                DateTime parentUpdateDateSeed = DateTime.Parse("01/01/2021");
                int      parentCreateCounter  = 0;

                Guid   aaaaGuid              = new Guid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa");
                string childOfAaaaKeyPrefix  = "11111111-1111-1111-1111-00000000000";
                string childOfAaaaNamePrefix = "Ch1111-";
                int    childACounter         = 0;

                Guid   bbbbGuid              = new Guid("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb");
                string childOfBbbbKeyPrefix  = "22222222-2222-2222-2222-00000000000";
                string childOfBbbbNamePrefix = "Ch2222-";
                int    childBCounter         = 0;

                Guid   ccccGuid              = new Guid("cccccccc-cccc-cccc-cccc-cccccccccccc");
                string childOfCcccKeyPrefix  = "33333333-3333-3333-3333-00000000000";
                string childOfCcccNamePrefix = "Ch3333-";
                int    childCCounter         = 0;

                Guid ddddGuid = new Guid("dddddddd-dddd-dddd-dddd-dddddddddddd");
                ////string childOfDdddKeyPrefix = "44444444-4444-4444-4444-00000000000";
                ////string childOfDdddNamePrefix = "Ch4444-";
                ////int childDDounter = 0;

                Guid   eeeeGuid              = new Guid("eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee");
                string childOfEeeeKeyPrefix  = "55555555-5555-5555-5555-00000000000";
                string childOfEeeeNamePrefix = "Ch5555-";
                int    childECounter         = 0;

                context.MyParents.AddRange(
                    new MyParentEntity
                {
                    MyParentKey     = aaaaGuid,
                    MyParentName    = "ParentA",
                    UpdateDateStamp = parentUpdateDateSeed.AddDays(++parentCreateCounter),
                    MyChilds        = new List <MyChildEntity>
                    {
                        new MyChildEntity()
                        {
                            MyChildKey         = new Guid(childOfAaaaKeyPrefix + Convert.ToString(++childACounter)),
                            MyParentUuidFk     = aaaaGuid,
                            MyChildName        = childOfAaaaNamePrefix + Convert.ToString(childACounter),
                            MyChildMagicStatus = MagicStatusValues.Four,
                            FavoriteColor      = Domain.Enums.FavoriteColorEnum.Red,
                            UpdateDateStamp    = DateTime.Parse("01/04/2020")
                        },
                        new MyChildEntity()
                        {
                            MyChildKey         = new Guid("11111111-1111-1111-1111-00000000000" + Convert.ToString(++childACounter)),
                            MyParentUuidFk     = aaaaGuid,
                            MyChildName        = childOfAaaaNamePrefix + Convert.ToString(childACounter),
                            MyChildMagicStatus = MagicStatusValues.Five,
                            FavoriteColor      = Domain.Enums.FavoriteColorEnum.Yellow,
                            UpdateDateStamp    = DateTime.Parse("01/05/2020")
                        },
                        new MyChildEntity()
                        {
                            MyChildKey         = new Guid("11111111-1111-1111-1111-00000000000" + Convert.ToString(++childACounter)),
                            MyParentUuidFk     = aaaaGuid,
                            MyChildName        = childOfAaaaNamePrefix + Convert.ToString(childACounter),
                            MyChildMagicStatus = MagicStatusValues.Six,
                            FavoriteColor      = Domain.Enums.FavoriteColorEnum.Black,
                            UpdateDateStamp    = DateTime.Parse("01/06/2020")
                        },
                        new MyChildEntity()
                        {
                            MyChildKey         = new Guid("11111111-1111-1111-1111-00000000000" + Convert.ToString(++childACounter)),
                            MyParentUuidFk     = aaaaGuid,
                            MyChildName        = childOfAaaaNamePrefix + Convert.ToString(childACounter),
                            MyChildMagicStatus = MagicStatusValues.NinetyNine,
                            FavoriteColor      = Domain.Enums.FavoriteColorEnum.White,
                            UpdateDateStamp    = DateTime.Parse("01/31/2020")
                        },
                        new MyChildEntity()
                        {
                            MyChildKey         = new Guid("11111111-1111-1111-1111-00000000000" + Convert.ToString(++childACounter)),
                            MyParentUuidFk     = aaaaGuid,
                            MyChildName        = childOfAaaaNamePrefix + Convert.ToString(childACounter),
                            MyChildMagicStatus = MagicStatusValues.Five,
                            FavoriteColor      = Domain.Enums.FavoriteColorEnum.Red,
                            UpdateDateStamp    = DateTime.Parse("02/05/2020")
                        },
                        new MyChildEntity()
                        {
                            MyChildKey         = new Guid("11111111-1111-1111-1111-00000000000" + Convert.ToString(++childACounter)),
                            MyParentUuidFk     = aaaaGuid,
                            MyChildName        = childOfAaaaNamePrefix + Convert.ToString(childACounter),
                            MyChildMagicStatus = MagicStatusValues.Six,
                            FavoriteColor      = Domain.Enums.FavoriteColorEnum.Yellow,
                            UpdateDateStamp    = DateTime.Parse("02/06/2020")
                        },
                        new MyChildEntity()
                        {
                            MyChildKey         = new Guid("11111111-1111-1111-1111-00000000000" + Convert.ToString(++childACounter)),
                            MyParentUuidFk     = aaaaGuid,
                            MyChildName        = childOfAaaaNamePrefix + Convert.ToString(childACounter),
                            MyChildMagicStatus = MagicStatusValues.NinetyNine,
                            FavoriteColor      = Domain.Enums.FavoriteColorEnum.Black,
                            UpdateDateStamp    = DateTime.Parse("02/29/2020")
                        },
                        new MyChildEntity()
                        {
                            MyChildKey         = new Guid("11111111-1111-1111-1111-00000000000" + Convert.ToString(++childACounter)),
                            MyParentUuidFk     = aaaaGuid,
                            MyChildName        = childOfAaaaNamePrefix + Convert.ToString(childACounter),
                            MyChildMagicStatus = MagicStatusValues.NinetyNine,
                            FavoriteColor      = Domain.Enums.FavoriteColorEnum.White,
                            UpdateDateStamp    = DateTime.Parse("02/29/2020")
                        }
                    }
                },
                    new MyParentEntity
                {
                    MyParentKey     = bbbbGuid,
                    MyParentName    = "ParentB",
                    UpdateDateStamp = parentUpdateDateSeed.AddDays(++parentCreateCounter),
                    MyChilds        = new List <MyChildEntity>
                    {
                        new MyChildEntity()
                        {
                            MyChildKey         = new Guid(childOfBbbbKeyPrefix + Convert.ToString(++childBCounter)),
                            MyParentUuidFk     = bbbbGuid,
                            MyChildName        = childOfBbbbNamePrefix + Convert.ToString(childBCounter),
                            MyChildMagicStatus = MagicStatusValues.Four,
                            FavoriteColor      = Domain.Enums.FavoriteColorEnum.Red,
                            UpdateDateStamp    = DateTime.Parse("01/04/2020")
                        },
                        new MyChildEntity()
                        {
                            MyChildKey         = new Guid(childOfBbbbKeyPrefix + Convert.ToString(++childBCounter)),
                            MyParentUuidFk     = bbbbGuid,
                            MyChildName        = childOfBbbbNamePrefix + Convert.ToString(childBCounter),
                            MyChildMagicStatus = MagicStatusValues.Five,
                            FavoriteColor      = Domain.Enums.FavoriteColorEnum.Yellow,
                            UpdateDateStamp    = DateTime.Parse("01/05/2020")
                        },
                        new MyChildEntity()
                        {
                            MyChildKey         = new Guid(childOfBbbbKeyPrefix + Convert.ToString(++childBCounter)),
                            MyParentUuidFk     = bbbbGuid,
                            MyChildName        = childOfBbbbNamePrefix + Convert.ToString(childBCounter),
                            MyChildMagicStatus = MagicStatusValues.Six,
                            FavoriteColor      = Domain.Enums.FavoriteColorEnum.Black,
                            UpdateDateStamp    = DateTime.Parse("01/06/2020")
                        },
                        new MyChildEntity()
                        {
                            MyChildKey         = new Guid(childOfBbbbKeyPrefix + Convert.ToString(++childBCounter)),
                            MyParentUuidFk     = bbbbGuid,
                            MyChildName        = childOfBbbbNamePrefix + Convert.ToString(childBCounter),
                            MyChildMagicStatus = MagicStatusValues.NinetyNine,
                            FavoriteColor      = Domain.Enums.FavoriteColorEnum.White,
                            UpdateDateStamp    = DateTime.Parse("01/31/2020")
                        },
                        new MyChildEntity()
                        {
                            MyChildKey         = new Guid(childOfBbbbKeyPrefix + Convert.ToString(++childBCounter)),
                            MyParentUuidFk     = bbbbGuid,
                            MyChildName        = childOfBbbbNamePrefix + Convert.ToString(childBCounter),
                            MyChildMagicStatus = MagicStatusValues.Five,
                            FavoriteColor      = Domain.Enums.FavoriteColorEnum.Red,
                            UpdateDateStamp    = DateTime.Parse("02/05/2020")
                        },
                        new MyChildEntity()
                        {
                            MyChildKey         = new Guid(childOfBbbbKeyPrefix + Convert.ToString(++childBCounter)),
                            MyParentUuidFk     = bbbbGuid,
                            MyChildName        = childOfBbbbNamePrefix + Convert.ToString(childBCounter),
                            MyChildMagicStatus = MagicStatusValues.Six,
                            FavoriteColor      = Domain.Enums.FavoriteColorEnum.Yellow,
                            UpdateDateStamp    = DateTime.Parse("02/29/2020")
                        }
                    }
                },
                    new MyParentEntity
                {
                    MyParentKey     = ccccGuid,
                    MyParentName    = "ParentC",
                    UpdateDateStamp = parentUpdateDateSeed.AddDays(++parentCreateCounter),
                    MyChilds        = new List <MyChildEntity>
                    {
                        new MyChildEntity()
                        {
                            MyChildKey         = new Guid(childOfCcccKeyPrefix + Convert.ToString(++childCCounter)),
                            MyParentUuidFk     = ccccGuid,
                            MyChildName        = childOfCcccNamePrefix + Convert.ToString(childCCounter),
                            MyChildMagicStatus = MagicStatusValues.NinetyEight,
                            FavoriteColor      = Domain.Enums.FavoriteColorEnum.Red,
                            UpdateDateStamp    = DateTime.Parse("02/29/2020")
                        }
                    }
                },
                    new MyParentEntity
                {
                    MyParentKey     = ddddGuid,
                    MyParentName    = "ParentD",
                    UpdateDateStamp = parentUpdateDateSeed.AddDays(++parentCreateCounter)
                                      /* no child on purpose */
                },
                    new MyParentEntity
                {
                    MyParentKey     = eeeeGuid,
                    MyParentName    = "ParentE",
                    UpdateDateStamp = parentUpdateDateSeed.AddDays(++parentCreateCounter),
                    MyChilds        = new List <MyChildEntity>
                    {
                        new MyChildEntity()
                        {
                            MyChildKey         = new Guid(childOfEeeeKeyPrefix + Convert.ToString(++childECounter)),
                            MyParentUuidFk     = eeeeGuid,
                            MyChildName        = childOfEeeeNamePrefix + Convert.ToString(childECounter),
                            MyChildMagicStatus = MagicStatusValues.NinetyNine,
                            FavoriteColor      = Domain.Enums.FavoriteColorEnum.Yellow,
                            /* this is a legit 99, but TOO FAR in the future */
                            UpdateDateStamp = DateTime.Parse("12/31/2020")
                        }
                    }
                });

                context.SaveChanges();
            }
        }