diff --git a/Controllers/BundlesController.cs b/Controllers/BundlesController.cs index 5c0fc0e..8b66139 100644 --- a/Controllers/BundlesController.cs +++ b/Controllers/BundlesController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using MyDarling.Models; namespace MyDarling.Controllers @@ -6,15 +7,20 @@ 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()); + } } } \ No newline at end of file diff --git a/Models/MyDarlingRepository.cs b/Models/MyDarlingRepository.cs index 07caff8..15f058c 100644 --- a/Models/MyDarlingRepository.cs +++ b/Models/MyDarlingRepository.cs @@ -2,31 +2,31 @@ using Microsoft.EntityFrameworkCore; namespace MyDarling.Models { - public class MyDarlingRepository : IRepository - { - private DataContext context; - public MyDarlingRepository(IServiceProvider provider) - { - context = provider.CreateScope().ServiceProvider.GetRequiredService(); - } - - public IQueryable Bundles => context.UnderwearBundles.Include(b => b.Figures); + public class MyDarlingRepository : IRepository + { + private DataContext DbContext { get; } + public MyDarlingRepository(IServiceProvider provider) + { + DbContext = provider.CreateScope().ServiceProvider.GetRequiredService(); + } - public void Add(UnderwearBundle b) - { - context.UnderwearBundles.Add(b); - context.SaveChanges(); - } + public IQueryable Bundles => DbContext.UnderwearBundles.Include(b => b.Figures); - public void Remove(UnderwearBundle b) - { - context.UnderwearBundles.Remove(b); - context.SaveChanges(); - } + public void Add(UnderwearBundle b) + { + DbContext.UnderwearBundles.Add(b); + DbContext.SaveChanges(); + } - public void Save() - { - context.SaveChanges(); - } - } + public void Remove(UnderwearBundle b) + { + DbContext.UnderwearBundles.Remove(b); + DbContext.SaveChanges(); + } + + public void Save() + { + DbContext.SaveChanges(); + } + } } \ No newline at end of file diff --git a/Views/Bundles/Edit.cshtml b/Views/Bundles/Edit.cshtml new file mode 100644 index 0000000..60a2420 --- /dev/null +++ b/Views/Bundles/Edit.cshtml @@ -0,0 +1,34 @@ +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers + + + + + + Bundles list + + + + + + + + + + + + + + + + + + + + + + +
#NameDescritionPrice
@Model.Id@Model.Name@Model.Description@Model.Price
+
+ + + \ No newline at end of file diff --git a/Views/Bundles/Index.cshtml b/Views/Bundles/Index.cshtml index 4f3a120..6c36cb7 100644 --- a/Views/Bundles/Index.cshtml +++ b/Views/Bundles/Index.cshtml @@ -25,7 +25,7 @@ { @bundle.Id - @bundle.Name + @bundle.Name @bundle.Description @bundle.Price