Example #1
0
        //  sqlite migrations are not as good as sql server
        //  https://docs.microsoft.com/en-us/aspnet/core/data/ef-rp/migrations?view=aspnetcore-5.0&tabs=visual-studio

        public AuthorizeController(ILogger <AuthorizeController> logger, RegistryDemo.Models.SqliteDBContext context)
        {
            _logger    = logger;
            _dbContext = context;
            Console.WriteLine();
            Console.WriteLine("Authorize Request Code Initialized");
        }
        //  sqlite migrations are not as good as sql server
        //  https://docs.microsoft.com/en-us/aspnet/core/data/ef-rp/migrations?view=aspnetcore-5.0&tabs=visual-studio

        public RegistryQueryController(ILogger <RegistryQueryController> logger, RegistryDemo.Models.SqliteDBContext context)
        {
            _logger    = logger;
            _dbContext = context;
            Console.WriteLine();
            context.Database.EnsureCreated();
            Console.WriteLine("DB has been Created - pre migrate");
            //       context.Database.Migrate();
            //       Console.WriteLine("Post migrate");
            if (context.RegisteredObjects.Any())
            {
                Console.WriteLine("context created - we have Registered Objects");
                return;
            }
            string      dbPath   = context.Database.GetConnectionString();
            string      tdPath   = "TestData.json";
            string      testData = System.IO.File.ReadAllText(tdPath, Encoding.UTF8);
            List <Maas> Ldo;

            Ldo = GetJsonGenericType <List <Maas> >(testData);
            foreach (Maas maas in Ldo)
            {
                RegisteredObject ro = new RegisteredObject
                {
                    Name           = maas.name,
                    Version        = maas.version,
                    Platform       = maas.platform,
                    Min_platform   = maas.min_platform,
                    Source         = maas.source,
                    Jurisdiction   = maas.jurisdiction,
                    User_authn     = maas.user_authn,
                    DateRegistered = maas.date,
                    Url            = maas.url,
                    Trust_registry = maas.trust_registry
                };
                context.Add(ro);
            }
            context.SaveChanges();
            Console.WriteLine("Completed Creation of base Registered Objtecs");
        }