Add edit page
This commit is contained in:
parent
9107bb6788
commit
e4b4105ec0
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using MyDarling.Models;
|
using MyDarling.Models;
|
||||||
|
|
||||||
namespace MyDarling.Controllers
|
namespace MyDarling.Controllers
|
||||||
@ -16,5 +17,10 @@ namespace MyDarling.Controllers
|
|||||||
{
|
{
|
||||||
return View(repository);
|
return View(repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionResult Edit(int id)
|
||||||
|
{
|
||||||
|
return View(repository.Bundles.Where(b => b.Id == id).FirstOrDefault());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,29 +4,29 @@ namespace MyDarling.Models
|
|||||||
{
|
{
|
||||||
public class MyDarlingRepository : IRepository
|
public class MyDarlingRepository : IRepository
|
||||||
{
|
{
|
||||||
private DataContext context;
|
private DataContext DbContext { get; }
|
||||||
public MyDarlingRepository(IServiceProvider provider)
|
public MyDarlingRepository(IServiceProvider provider)
|
||||||
{
|
{
|
||||||
context = provider.CreateScope().ServiceProvider.GetRequiredService<DataContext>();
|
DbContext = provider.CreateScope().ServiceProvider.GetRequiredService<DataContext>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IQueryable<UnderwearBundle> Bundles => context.UnderwearBundles.Include(b => b.Figures);
|
public IQueryable<UnderwearBundle> Bundles => DbContext.UnderwearBundles.Include(b => b.Figures);
|
||||||
|
|
||||||
public void Add(UnderwearBundle b)
|
public void Add(UnderwearBundle b)
|
||||||
{
|
{
|
||||||
context.UnderwearBundles.Add(b);
|
DbContext.UnderwearBundles.Add(b);
|
||||||
context.SaveChanges();
|
DbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(UnderwearBundle b)
|
public void Remove(UnderwearBundle b)
|
||||||
{
|
{
|
||||||
context.UnderwearBundles.Remove(b);
|
DbContext.UnderwearBundles.Remove(b);
|
||||||
context.SaveChanges();
|
DbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
context.SaveChanges();
|
DbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
34
Views/Bundles/Edit.cshtml
Normal file
34
Views/Bundles/Edit.cshtml
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Bundles list</title>
|
||||||
|
<link href="/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<container>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">#</th>
|
||||||
|
<th scope="col">Name</th>
|
||||||
|
<th scope="col">Descrition</th>
|
||||||
|
<th scope="col">Price</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">@Model.Id</th>
|
||||||
|
<td>@Model.Name</a></td>
|
||||||
|
<td>@Model.Description</td>
|
||||||
|
<td>@Model.Price</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</container>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
@ -25,7 +25,7 @@
|
|||||||
{
|
{
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">@bundle.Id</th>
|
<th scope="row">@bundle.Id</th>
|
||||||
<td>@bundle.Name</td>
|
<td><a asp-action="Edit" asp-route-id="@bundle.Id">@bundle.Name</a></td>
|
||||||
<td>@bundle.Description</td>
|
<td>@bundle.Description</td>
|
||||||
<td>@bundle.Price</td>
|
<td>@bundle.Price</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
Loading…
Reference in New Issue
Block a user