コード例 #1
0
        public async Task <bool> RefreshStoreFromCensus()
        {
            IEnumerable <CensusItemModel> items = new List <CensusItemModel>();

            try
            {
                items = await _censusItem.GetAllItems();
            }
            catch
            {
                _logger.LogError("Census API query failed: get all Items. Refreshing store from backup...");
                return(false);
            }

            if (items != null && items.Any())
            {
                await UpsertRangeAsync(items.Select(ConvertToDbModel));

                _logger.LogInformation($"Refreshed Items store: {items.Count()} entries");

                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        public async Task RefreshStore()
        {
            bool refreshStore  = true;
            bool anyItems      = false;
            bool anyCategories = false;

            using (var factory = _dbContextHelper.GetFactory())
            {
                var dbContext = factory.GetDbContext();

                anyItems = await dbContext.Items.AnyAsync();

                if (anyItems == true)
                {
                    anyCategories = await dbContext.ItemCategories.AnyAsync();
                }

                refreshStore = (anyItems == false || anyCategories == false);
            }

            if (refreshStore != true)
            {
                return;
            }

            var itemCategories = await _censusItemCategory.GetAllItemCategories();

            if (itemCategories != null)
            {
                await UpsertRangeAsync(itemCategories.Select(ConvertToDbModel));
            }

            var items = await _censusItem.GetAllItems();

            if (items != null)
            {
                await UpsertRangeAsync(items.Select(ConvertToDbModel));
            }
        }