47 lines
901 B
C#
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");
|
|
}
|
|
}
|
|
} |