public async Task <bool> RefreshStoreFromCensus() { IEnumerable <CensusItemCategoryModel> itemCategories = new List <CensusItemCategoryModel>(); try { itemCategories = await _censusItemCategory.GetAllItemCategories(); } catch { _logger.LogError("Census API query failed: get all Item Categories. Refreshing store from backup..."); return(false); } if (itemCategories != null && itemCategories.Any()) { await UpsertRangeAsync(itemCategories.Select(ConvertToDbModel)); _logger.LogInformation($"Refreshed Item Categories store: {itemCategories.Count()} entries"); SendStoreRefreshEventMessage(StoreRefreshSource.CensusApi); return(true); } else { return(false); } }
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)); } }