0
0

Add delete action for bundles controller

This commit is contained in:
Sergey Chebotar 2023-02-16 08:46:04 +03:00
parent e4b4105ec0
commit b20759f205
2 changed files with 12 additions and 0 deletions

View File

@ -22,5 +22,15 @@ namespace MyDarling.Controllers
{ {
return View(repository.Bundles.Where(b => b.Id == id).FirstOrDefault()); 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");
}
} }
} }

View File

@ -18,6 +18,7 @@
<th scope="col">Name</th> <th scope="col">Name</th>
<th scope="col">Descrition</th> <th scope="col">Descrition</th>
<th scope="col">Price</th> <th scope="col">Price</th>
<th scope="col">Actions</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -28,6 +29,7 @@
<td><a asp-action="Edit" asp-route-id="@bundle.Id">@bundle.Name</a></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>
<td><a asp-action="Delete" asp-route-id="@bundle.Id">Delete</a></td>
</tr> </tr>
} }
</tbody> </tbody>