Example #1
0
        public Task UpdateDataAsync()
        {
            return(Task.Run(() =>
            {
                var basePodcasts = GetBasePodcastsFromJson();

                var properties = basePodcasts.GetType().GetProperties();
                foreach (var prop in properties)
                {
                    var existingBasePodcasts = Context.BasePodcast.ToImmutableList();
                    var podcastList = (IEnumerable <BasePodcastJsonObject>)prop.GetValue(basePodcasts);
                    var propertyName = prop.Name;

                    Logger.LogInformation("BasePodcast Category: " + propertyName);

                    var basePodcastJsonObjects = FindNonExisting(podcastList, existingBasePodcasts).ToList();
                    if (!basePodcastJsonObjects.Any())
                    {
                        continue;
                    }
                    BasePodcasts.AddRange(basePodcastJsonObjects.Select(d => d.CreateBasePodcast()));
                }

                Save().Wait();

                Logger.LogInformation("Updating base podcasts is complete...");
            }));
        }
Example #2
0
        private async Task Save()
        {
            if (BasePodcasts.Any())
            {
                await Context.BasePodcast.AddRangeAsync(BasePodcasts).ConfigureAwait(false);

                await Context.SaveChangesAsync().ConfigureAwait(false);
            }
            Context.Dispose();
        }