Files
eShopOnWeb/src/Web/Pages/Admin/EditCatalogItem.cshtml.cs
Eric Fleming f3f74a342e 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
2019-12-10 22:04:59 -05:00

40 lines
1.3 KiB
C#

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");
}
}
}