Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostResetAdminDatabaseAsync()
        {
            await DB.Database.EnsureDeletedAsync();

            ParkAdminDatabaseInitializer.Initialize(DB);
            ShowNotify("操作成功,请重新登录");
            return(UIHelper.Result());
        }
Ejemplo n.º 2
0
        // https://docs.microsoft.com/zh-cn/aspnet/core/data/ef-rp/intro
        private static void CreateDbIfNotExists(IHost host)
        {
            using var scope = host.Services.CreateScope();
            var services = scope.ServiceProvider;

            try
            {
                var context     = services.GetRequiredService <ParkAdminContext>();
                var parkContext = services.GetRequiredService <ParkContext>();
                ParkAdminDatabaseInitializer.Initialize(context);
                ParkDatabaseInitializer.Initialize(parkContext);
            }
            catch (Exception ex)
            {
                var logger = services.GetRequiredService <ILogger <Program> >();
                logger.LogError(ex, "创建数据库时发生错误!");
            }
        }