2023-02-16 07:47:09 +03:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-02-16 08:28:59 +03:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-02-16 07:47:09 +03:00
|
|
|
using MyDarling.Models;
|
|
|
|
|
|
|
|
namespace MyDarling.Controllers
|
|
|
|
{
|
|
|
|
public class BundlesController : Controller
|
|
|
|
{
|
|
|
|
private IRepository repository;
|
2023-02-16 08:28:59 +03:00
|
|
|
|
2023-02-16 07:47:09 +03:00
|
|
|
public BundlesController(IRepository repository)
|
|
|
|
{
|
|
|
|
this.repository = repository;
|
|
|
|
}
|
2023-02-16 08:28:59 +03:00
|
|
|
|
2023-02-16 07:47:09 +03:00
|
|
|
public ActionResult Index()
|
|
|
|
{
|
|
|
|
return View(repository);
|
|
|
|
}
|
2023-02-16 08:28:59 +03:00
|
|
|
|
|
|
|
public ActionResult Edit(int id)
|
|
|
|
{
|
|
|
|
return View(repository.Bundles.Where(b => b.Id == id).FirstOrDefault());
|
|
|
|
}
|
2023-02-16 08:46:04 +03:00
|
|
|
|
|
|
|
public ActionResult Delete(int id)
|
|
|
|
{
|
|
|
|
var bundle = repository.Bundles.Where(b => b.Id == id).FirstOrDefault();
|
|
|
|
if (bundle != null)
|
|
|
|
{
|
|
|
|
repository.Remove(bundle);
|
|
|
|
}
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
}
|
2023-02-16 09:01:18 +03:00
|
|
|
|
|
|
|
public ActionResult Add()
|
|
|
|
{
|
|
|
|
return View();
|
|
|
|
}
|
|
|
|
[HttpPost]
|
|
|
|
public ActionResult Add(UnderwearBundle b)
|
|
|
|
{
|
|
|
|
repository.Add(b);
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
}
|
2023-02-16 07:47:09 +03:00
|
|
|
}
|
|
|
|
}
|