mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
50 lines
1.2 KiB
C#
50 lines
1.2 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using ProductCatalog.Models;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace ProductCatalog.Controllers
|
|
{
|
|
public class ProductCatalogController : Controller
|
|
{
|
|
private ProductCatalogContext _context;
|
|
|
|
public ProductCatalogController (ProductCatalogContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Index()
|
|
{
|
|
ViewData["page"] = "index";
|
|
return View(_context.Products.AsEnumerable());
|
|
}
|
|
|
|
// POST api/ProductCatalog/Add
|
|
public IActionResult Add(Product p)
|
|
{
|
|
try
|
|
{
|
|
_context.Products.Add(p);
|
|
_context.SaveChanges();
|
|
return Redirect("/ProductCatalog/Index");
|
|
} catch (Exception)
|
|
{
|
|
return Redirect("/ProductCatalog/Index");
|
|
}
|
|
}
|
|
|
|
public IActionResult Report1()
|
|
{
|
|
ViewData["page"] = "report1";
|
|
return View();
|
|
}
|
|
|
|
public IActionResult Report2()
|
|
{
|
|
ViewData["page"] = "report2";
|
|
return View();
|
|
}
|
|
}
|
|
} |