Admin page (#324)

* Updates based on documentation

* Getting the build passing

* Getting app functioning

* A few cleanups to confirm it's working as expected

* Fixing functional tests

* Updating dockerfile for 3.0

* Functional Tests now run sequentially

* Updating to latest version of moq

* Adding migration for post 3.0 upgrades

* Removing commented out lines

* Moving address and catalogitemordered configuration in to classes that own them

* Adding admin user

* Adding admin catalog screen

- will also only display menu option if user is logged in as an admin

* WIP - squash this

* Allow user to edit a catalog item

* Adding entry for new service

* Invalidating cache after catalog item update

- also a little bit of cleanup

* Fixing bad merge

* Removing Picture Uri and making Id readonly

* Adjusting style in menu dropdown so all options are shown

* Creating Cache helpers with unit tests
This commit is contained in:
Eric Fleming
2019-12-10 20:04:59 -07:00
committed by Steve Smith
parent 539d8c689d
commit f3f74a342e
20 changed files with 360 additions and 45 deletions

View File

@@ -3,7 +3,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.eShopWeb.Web.ViewModels;
using Microsoft.Extensions.Caching.Memory;
using System;
using Microsoft.eShopWeb.Web.Extensions;
namespace Microsoft.eShopWeb.Web.Services
{
@@ -11,10 +11,6 @@ namespace Microsoft.eShopWeb.Web.Services
{
private readonly IMemoryCache _cache;
private readonly CatalogViewModelService _catalogViewModelService;
private static readonly string _brandsKey = "brands";
private static readonly string _typesKey = "types";
private static readonly string _itemsKeyTemplate = "items-{0}-{1}-{2}-{3}";
private static readonly TimeSpan _defaultCacheDuration = TimeSpan.FromSeconds(30);
public CachedCatalogViewModelService(IMemoryCache cache,
CatalogViewModelService catalogViewModelService)
@@ -25,28 +21,29 @@ namespace Microsoft.eShopWeb.Web.Services
public async Task<IEnumerable<SelectListItem>> GetBrands()
{
return await _cache.GetOrCreateAsync(_brandsKey, async entry =>
return await _cache.GetOrCreateAsync(CacheHelpers.GenerateBrandsCacheKey(), async entry =>
{
entry.SlidingExpiration = _defaultCacheDuration;
entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration;
return await _catalogViewModelService.GetBrands();
});
}
public async Task<CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, int? brandId, int? typeId)
{
string cacheKey = String.Format(_itemsKeyTemplate, pageIndex, itemsPage, brandId, typeId);
var cacheKey = CacheHelpers.GenerateCatalogItemCacheKey(pageIndex, Constants.ITEMS_PER_PAGE, brandId, typeId);
return await _cache.GetOrCreateAsync(cacheKey, async entry =>
{
entry.SlidingExpiration = _defaultCacheDuration;
entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration;
return await _catalogViewModelService.GetCatalogItems(pageIndex, itemsPage, brandId, typeId);
});
}
public async Task<IEnumerable<SelectListItem>> GetTypes()
{
return await _cache.GetOrCreateAsync(_typesKey, async entry =>
return await _cache.GetOrCreateAsync(CacheHelpers.GenerateTypesCacheKey(), async entry =>
{
entry.SlidingExpiration = _defaultCacheDuration;
entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration;
return await _catalogViewModelService.GetTypes();
});
}