You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1009 B
44 lines
1009 B
using ContosoPizza.Models;
|
|
using ContosoPizza.Services;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
namespace ContosoPizza.Pages
|
|
{
|
|
public class PizzaListModel : PageModel
|
|
{
|
|
private readonly PizzaService _service;
|
|
public IList<Pizza> PizzaList { get; set; } = new List<Pizza>();
|
|
|
|
[BindProperty]
|
|
public Pizza NewPizza { get; set; } = default;
|
|
|
|
public PizzaListModel(PizzaService service)
|
|
{
|
|
_service = service;
|
|
}
|
|
|
|
public void OnGet()
|
|
{
|
|
PizzaList = _service.GetPizzas();
|
|
}
|
|
|
|
public IActionResult OnPost()
|
|
{
|
|
if (ModelState.IsValid && NewPizza != null)
|
|
{
|
|
_service.AddPizza(NewPizza);
|
|
|
|
}
|
|
|
|
return RedirectToAction("Get");
|
|
}
|
|
|
|
public IActionResult OnPostDelete(int id)
|
|
{
|
|
_service.DeletePizza(id);
|
|
|
|
return RedirectToAction("Get");
|
|
}
|
|
}
|
|
}
|
|
|