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);
            }
        }
        public static async Task <User> GetOrAdd(this ResourcesContext context, ClaimsPrincipal currentUser)
        {
            var user = await context.Users.FindAsync(currentUser.Identity.Name);

            var avatar = currentUser.GetAvatarUrl();

            if (user == null)
            {
                user = new User
                {
                    Login     = currentUser.Identity.Name,
                    AvatarUrl = currentUser.GetAvatarUrl()
                };

                await context.AddAsync(user);
            }
            else if (user.AvatarUrl != avatar)
            {
                user.AvatarUrl = avatar;
            }

            return(user);
        }