Example #1
0
        //Handles the Migration Programmatic
        public static async Task ManageDataAsync(IHost host)
        {
            try
            {
                //This technique is used to obtain references to services
                //Normally I would just inject these services but you cant use a constructor in a static class.
                using var svcScope = host.Services.CreateScope();
                var svcProvider = svcScope.ServiceProvider;

                //The services  will run your migrations
                var dbContextSvc = svcProvider.GetRequiredService <ApplicationDbContext>();
                await dbContextSvc.Database.MigrateAsync();

                var userManager  = svcProvider.GetRequiredService <UserManager <FPUser> >();
                var roleManager  = svcProvider.GetRequiredService <RoleManager <IdentityRole> >();
                var imageService = svcProvider.GetRequiredService <IImageService>();
                await ContextSeed.SeedRolesAsync(roleManager);

                await ContextSeed.SeedDefaultUserAsync(userManager, imageService);

                //var settings = svcProvider.GetRequiredService<IOptions<AdminSettings>>();

                //await SeedDataAsync(seedConfigSvc);
            }
            catch (PostgresException ex)
            {
                Console.WriteLine($"Exception while running Manage Data => {ex}");
            }
        }
Example #2
0
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            await DataHelper.ManageDataAsync(host);

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    var context      = services.GetRequiredService <ApplicationDbContext>();
                    var userManager  = services.GetRequiredService <UserManager <FPUser> >();
                    var roleManager  = services.GetRequiredService <RoleManager <IdentityRole> >();
                    var imageService = services.GetRequiredService <IImageService>();
                    await ContextSeed.SeedRolesAsync(roleManager);

                    await ContextSeed.SeedDefaultUserAsync(userManager, imageService);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }
            host.Run();
        }
Example #3
0
        //dodavanje podataka prilikom pokretanja aplikacije
        public async static Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    var context     = services.GetRequiredService <ApplicationDbContext>();
                    var userManager = services.GetRequiredService <UserManager <Korisnik> >();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    await ContextSeed.SeedRolesAsync(userManager, roleManager);

                    await ContextSeed.Administratori(userManager, roleManager);

                    await ContextSeed.Predavaci(userManager, roleManager);

                    //await ContextSeed.Polaznik(userManager,roleManager);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "Došlo je do pogreške prilikom postavljanja DB-a.");
                }
            }
            host.Run();
        }
Example #4
0
        public async static Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    var context     = services.GetRequiredService <FagElGamousContext>();
                    var userManager = services.GetRequiredService <UserManager <AppUser> >();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    await ContextSeed.SeedRolesAsync(userManager, roleManager);

                    await ContextSeed.SeedAdminAsync(userManager, roleManager);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }
            host.Run();
        }
Example #5
0
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    var context = scope.ServiceProvider.GetService <RealStateDbContext>();
                    context.Database.EnsureDeleted();
                    context.Database.Migrate();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    await ContextSeed.SeedRolesAsync(roleManager);

                    var userManager = services.GetRequiredService <UserManager <AppUser> >();
                    await ContextSeed.SeedUsersAsync(userManager);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "An error occurred while migrating the database.");
                }
            }

            // run the web app
            host.Run();
        }
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                //try
                //{
                var context     = services.GetRequiredService <ApplicationDbContext>();
                var userManager = services.GetRequiredService <UserManager <IdentityUser> >();
                var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                await ContextSeed.SeedRolesAsync(userManager, roleManager);

                await ContextSeed.SeedSuperAdminAsync(userManager);

                await ContextSeed.SeedIdentityUsersAsync(userManager);

                await ContextSeed.SeedKanbanTasksAsync(new KanbanTaskManager(context), userManager);

                //}
                //catch (Exception ex)
                //{
                //    var logger = loggerFactory.CreateLogger<Program>();
                //    logger.LogError(ex, "An error occurred seeding the DB.");
                //}
            }
            host.Run();
        }
Example #7
0
        public async static Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    System.Diagnostics.Debug.WriteLine("Program Started");
                    var context     = services.GetRequiredService <SeniorLibraryContext>();
                    var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    await ContextSeed.SeedRolesAsync(userManager, roleManager);

                    await ContextSeed.SeedSuperAdminAsync(userManager, roleManager);

                    //Must have users.json in project folder!
                    await ContextSeed.AddUserAsync(userManager, roleManager);

                    await ContextSeed.AddBookAsync(context);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }
            host.Run();
        }
Example #8
0
        //public static void Main(string[] args)
        //{
        //    CreateHostBuilder(args).Build().Run();
        //}

        //public static IHostBuilder CreateHostBuilder(string[] args) =>
        //    Host.CreateDefaultBuilder(args)
        //        .ConfigureWebHostDefaults(webBuilder =>
        //        {
        //            webBuilder.UseStartup<Startup>();
        //        });

        public async static Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    var context     = services.GetRequiredService <ApplicationDbContext>();
                    var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    await ContextSeed.SeedRolesAsync(userManager, roleManager);

                    await ContextSeed.SeedSuperAdminAsync(userManager, roleManager);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "Une erreur s'est produite lors de l'amorçage de la base de données.");
                }
            }
            host.Run();
        }
Example #9
0
        //public static void Main(string[] args)
        //{
        //    CreateHostBuilder(args).Build().Run();
        //}
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var            services      = scope.ServiceProvider;
                var            UserContext   = services.GetRequiredService <ApplicationDbContext>();
                HotelContext   hotelContext  = scope.ServiceProvider.GetService <HotelContext>();
                ISeederService seederService = scope.ServiceProvider.GetService <ISeederService>();
                //If database doesent exist, run the seeder from movieservice
                bool DatabaseDoesNotExist = hotelContext.Database.EnsureCreated();
                if (DatabaseDoesNotExist)
                {
                    seederService.SeedDataBase();
                }
                ;
                if (!UserContext.Database.EnsureCreated())
                {
                    UserContext.Database.Migrate();
                    var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    await ContextSeed.SeedRolesAsync(userManager, roleManager);

                    await ContextSeed.SeedAdminAsync(userManager, roleManager);
                }
            }
            host.Run();
        }
Example #10
0
 private static void seedAdmin(IHost host)
 {
     using (var scope = host.Services.CreateScope())
     {
         var services      = scope.ServiceProvider;
         var loggerFactory = services.GetRequiredService <ILoggerFactory>();
         try
         {
             var context     = services.GetRequiredService <DBContext>();
             var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
             var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
             ContextSeed.SeedRolesAsync(userManager, roleManager).Wait();
             ContextSeed.SeedSuperAdminAsync(userManager, roleManager).Wait();
         }
         catch (Exception ex)
         {
             var logger = loggerFactory.CreateLogger <Program>();
             logger.LogError(ex, "An error occurred seeding the DB.");
         }
     }
 }
Example #11
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            //Dependancy Injection to bring in all middleware services using in the app
            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                //Everything here surrounded in try catch incase something breaks
                try
                {
                    //context for the database
                    var context = services.GetRequiredService <ApplicationDbContext>();
                    //userMgr handles all the identityusers
                    var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    //roleMgr handles all the identityroles
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    //check to make sure database is created, apply the latest migrations just in case.
                    context.Database.EnsureCreated();
                    //if no roles exist in db seed roles
                    if (!context.Roles.Any())
                    {
                        ContextSeed.SeedRolesAsync(userManager, roleManager).GetAwaiter().GetResult();
                    }
                    //if no users exist in db seed users and assign them to default roles
                    if (!context.Users.Any())
                    {
                        ContextSeed.SeedSuperAdminAsync(userManager, roleManager).GetAwaiter().GetResult();
                    }
                }
                catch (Exception e)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(e, "Error occurred seeding the db. Check program.cs");
                }
            }
            host.Run();
        }
Example #12
0
        public static async Task ManageData(IHost host)
        {
            try
            {
                // This technique is used to obtain references to services
                // Normally I would just inject these services but you can't use a constructor in
                // A static class...
                using var svcScope = host.Services.CreateScope();
                var svcProvider = svcScope.ServiceProvider;

                // The service will run your migrations
                var dbContextSvc = svcProvider.GetRequiredService <ApplicationDbContext>();
                await dbContextSvc.Database.MigrateAsync();

                // Seed Data
                var services    = svcScope.ServiceProvider;
                var context     = services.GetRequiredService <ApplicationDbContext>();
                var usermanager = services.GetRequiredService <UserManager <BTUser> >();
                var rolemanager = services.GetRequiredService <RoleManager <IdentityRole> >();
                await ContextSeed.SeedRolesAsync(rolemanager);

                await ContextSeed.SeedDefaultUsersAsync(usermanager);

                await ContextSeed.SeedDefaultTicketPropsAsync(context);

                await ContextSeed.SeedProjectsAsync(context);

                await ContextSeed.SeedProjectUsersAsync(context, usermanager);

                await ContextSeed.SeedTicketsAsync(context, usermanager);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception while running Manage Data -> {ex}");
            }
        }
Example #13
0
        public async static Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    var context     = services.GetRequiredService <SystemContext>();
                    var userManager = services.GetRequiredService <UserManager <User> >();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    await ContextSeed.SeedRolesAsync(userManager, roleManager);

                    await ContextSeed.SeedSuperAdminAsync(userManager, roleManager);

                    Status status = context.Statuses.FirstOrDefault(s => s.StatusName.ToLower().Equals("в обработке"));
                    if (status == null)
                    {
                        context.Statuses.Add(new Status()
                        {
                            StatusName = "В обработке"
                        });
                        context.SaveChanges();
                    }
                    status = context.Statuses.FirstOrDefault(s => s.StatusName.ToLower().Equals("отменена"));
                    if (status == null)
                    {
                        context.Statuses.Add(new Status()
                        {
                            StatusName = "Отменена"
                        });
                        context.SaveChanges();
                    }
                    status = context.Statuses.FirstOrDefault(s => s.StatusName.ToLower().Equals("в пользовании"));
                    if (status == null)
                    {
                        context.Statuses.Add(new Status()
                        {
                            StatusName = "В пользовании"
                        });
                        context.SaveChanges();
                    }
                    status = context.Statuses.FirstOrDefault(s => s.StatusName.ToLower().Equals("возвращено"));
                    if (status == null)
                    {
                        context.Statuses.Add(new Status()
                        {
                            StatusName = "возвращено"
                        });
                        context.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }
            host.Run();
        }