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:
committed by
Steve Smith
parent
539d8c689d
commit
f3f74a342e
38
src/Web/Pages/Admin/EditCatalogItem.cshtml
Normal file
38
src/Web/Pages/Admin/EditCatalogItem.cshtml
Normal file
@@ -0,0 +1,38 @@
|
||||
@page
|
||||
@{
|
||||
ViewData["Title"] = "Admin - Edit Catalog";
|
||||
@model EditCatalogItemModel
|
||||
}
|
||||
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<img class="esh-catalog-thumbnail" src="@Model.CatalogModel.PictureUri" />
|
||||
<form method="post">
|
||||
<div class="form-group">
|
||||
<label asp-for="CatalogModel.Name"></label>
|
||||
<input asp-for="CatalogModel.Name" class="form-control" />
|
||||
<span asp-validation-for="CatalogModel.Name"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="CatalogModel.Price"></label>
|
||||
<input asp-for="CatalogModel.Price" class="form-control" />
|
||||
<span asp-validation-for="CatalogModel.Price"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="CatalogModel.Id"></label>
|
||||
<input asp-for="CatalogModel.Id" readonly class="form-control" />
|
||||
<span asp-validation-for="CatalogModel.Id"></span>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<input type="submit" value="Save" class="esh-catalog-button" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@section Scripts {
|
||||
<partial name="_ValidationScriptsPartial" />
|
||||
}
|
||||
39
src/Web/Pages/Admin/EditCatalogItem.cshtml.cs
Normal file
39
src/Web/Pages/Admin/EditCatalogItem.cshtml.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Constants;
|
||||
using Microsoft.eShopWeb.Web.Interfaces;
|
||||
using Microsoft.eShopWeb.Web.ViewModels;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopWeb.Web.Pages.Admin
|
||||
{
|
||||
[Authorize(Roles = AuthorizationConstants.Roles.ADMINISTRATORS)]
|
||||
public class EditCatalogItemModel : PageModel
|
||||
{
|
||||
private readonly ICatalogItemViewModelService _catalogItemViewModelService;
|
||||
|
||||
public EditCatalogItemModel(ICatalogItemViewModelService catalogItemViewModelService)
|
||||
{
|
||||
_catalogItemViewModelService = catalogItemViewModelService;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public CatalogItemViewModel CatalogModel { get; set; } = new CatalogItemViewModel();
|
||||
|
||||
public async Task OnGet(CatalogItemViewModel catalogModel)
|
||||
{
|
||||
CatalogModel = catalogModel;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
await _catalogItemViewModelService.UpdateCatalogItem(CatalogModel);
|
||||
}
|
||||
|
||||
return RedirectToPage("/Admin/Index");
|
||||
}
|
||||
}
|
||||
}
|
||||
45
src/Web/Pages/Admin/Index.cshtml
Normal file
45
src/Web/Pages/Admin/Index.cshtml
Normal file
@@ -0,0 +1,45 @@
|
||||
@page
|
||||
@{
|
||||
ViewData["Title"] = "Admin - Catalog";
|
||||
@model IndexModel
|
||||
}
|
||||
<section class="esh-catalog-hero">
|
||||
<div class="container">
|
||||
<img class="esh-catalog-title" src="~/images/main_banner_text.png" />
|
||||
</div>
|
||||
</section>
|
||||
<section class="esh-catalog-filters">
|
||||
<div class="container">
|
||||
<form method="get">
|
||||
<label class="esh-catalog-label" data-title="brand">
|
||||
<select asp-for="@Model.CatalogModel.BrandFilterApplied" asp-items="@Model.CatalogModel.Brands" class="esh-catalog-filter"></select>
|
||||
</label>
|
||||
<label class="esh-catalog-label" data-title="type">
|
||||
<select asp-for="@Model.CatalogModel.TypesFilterApplied" asp-items="@Model.CatalogModel.Types" class="esh-catalog-filter"></select>
|
||||
</label>
|
||||
<input class="esh-catalog-send" type="image" src="images/arrow-right.svg" />
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
<div class="container">
|
||||
@if (Model.CatalogModel.CatalogItems.Any())
|
||||
{
|
||||
<partial name="_pagination" for="CatalogModel.PaginationInfo" />
|
||||
|
||||
<div class="esh-catalog-items row">
|
||||
@foreach (var catalogItem in Model.CatalogModel.CatalogItems)
|
||||
{
|
||||
<div class="esh-catalog-item col-md-4">
|
||||
<partial name="_editCatalog" for="@catalogItem" />
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<partial name="_pagination" for="CatalogModel.PaginationInfo" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="esh-catalog-items row">
|
||||
THERE ARE NO RESULTS THAT MATCH YOUR SEARCH
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
35
src/Web/Pages/Admin/Index.cshtml.cs
Normal file
35
src/Web/Pages/Admin/Index.cshtml.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Constants;
|
||||
using Microsoft.eShopWeb.Web.Extensions;
|
||||
using Microsoft.eShopWeb.Web.Services;
|
||||
using Microsoft.eShopWeb.Web.ViewModels;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopWeb.Web.Pages.Admin
|
||||
{
|
||||
[Authorize(Roles = AuthorizationConstants.Roles.ADMINISTRATORS)]
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
private readonly ICatalogViewModelService _catalogViewModelService;
|
||||
private readonly IMemoryCache _cache;
|
||||
|
||||
public IndexModel(ICatalogViewModelService catalogViewModelService, IMemoryCache cache)
|
||||
{
|
||||
_catalogViewModelService = catalogViewModelService;
|
||||
_cache = cache;
|
||||
}
|
||||
|
||||
public CatalogIndexViewModel CatalogModel { get; set; } = new CatalogIndexViewModel();
|
||||
|
||||
public async Task OnGet(CatalogIndexViewModel catalogModel, int? pageId)
|
||||
{
|
||||
var cacheKey = CacheHelpers.GenerateCatalogItemCacheKey(pageId.GetValueOrDefault(), Constants.ITEMS_PER_PAGE, catalogModel.BrandFilterApplied, catalogModel.TypesFilterApplied);
|
||||
|
||||
_cache.Remove(cacheKey);
|
||||
|
||||
CatalogModel = await _catalogViewModelService.GetCatalogItems(pageId.GetValueOrDefault(), Constants.ITEMS_PER_PAGE, catalogModel.BrandFilterApplied, catalogModel.TypesFilterApplied);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user