0
0
MyDarling/Controllers/BundlesController.cs
2023-02-16 09:01:18 +03:00

47 lines
901 B
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MyDarling.Models;
namespace MyDarling.Controllers
{
public class BundlesController : Controller
{
private IRepository repository;
public BundlesController(IRepository repository)
{
this.repository = repository;
}
public ActionResult Index()
{
return View(repository);
}
public ActionResult Edit(int id)
{
return View(repository.Bundles.Where(b => b.Id == id).FirstOrDefault());
}
public ActionResult Delete(int id)
{
var bundle = repository.Bundles.Where(b => b.Id == id).FirstOrDefault();
if (bundle != null)
{
repository.Remove(bundle);
}
return RedirectToAction("Index");
}
public ActionResult Add()
{
return View();
}
[HttpPost]
public ActionResult Add(UnderwearBundle b)
{
repository.Add(b);
return RedirectToAction("Index");
}
}
}