private async Task AddSystemUser(ResourcesContext context, CancellationToken token)
        {
            await context.Users.AddAsync(User.GetSystemUser(), token);

            await context.AddOrUpdateSetting(SystemUserSettingKey, "true");

            await context.SaveChangesAsync(token);
        }
        private async Task Seed(ResourcesContext context, CancellationToken token)
        {
            var resourcesPath = Path.GetFullPath("data/resources.json");

            if (File.Exists(resourcesPath))
            {
                var json   = JObject.Parse(System.IO.File.ReadAllText(resourcesPath));
                var groups = json.SelectToken("groups").Select(g => g.ToObject <Models.ResourcesGroup>()).ToList();

                var existingGroups    = context.Groups.Include(it => it.Resources).ToList();
                var existingResources = existingGroups.SelectMany(it => it.Resources).ToList();

                foreach (var group in groups)
                {
                    if (!existingGroups.Contains(group))
                    {
                        Log.Information("Seeding data: add group {@group}", group.Name);
                        await context.AddAsync(group, token);
                    }

                    if (group.Resources != null)
                    {
                        foreach (var resource in group.Resources)
                        {
                            if (!existingResources.Contains(resource))
                            {
                                Log.Information("Seeding data: add resource {@resource}", resource.Name);
                                await context.AddAsync(resource, token);
                            }
                        }
                    }
                }

                await context.AddOrUpdateSetting(DataSeededSettingKey, "true");

                await context.SaveChangesAsync(token);
            }
        }