Skip to content

Commit

Permalink
added category details page
Browse files Browse the repository at this point in the history
  • Loading branch information
mobeendev committed Jun 29, 2024
1 parent 1d0e670 commit d5411bc
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
35 changes: 32 additions & 3 deletions Areas/Admin/Controllers/CategoryController.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
using BethanysPieShop.Models;
using BethanysPieShop.ViewModels;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;

namespace BethanysPieShop.Controllers.Admin
{
[Area("Admin")]
public class CategoryController : Controller
{
private readonly BethanysPieShopDbContext _bethanysPieShopDbContext;
private readonly BethanysPieShopDbContext _context;

public CategoryController(BethanysPieShopDbContext bethanysPieShopDbContext)
{
_bethanysPieShopDbContext = bethanysPieShopDbContext;
_context = bethanysPieShopDbContext;
}

public IActionResult Index()
{
var allPies = _bethanysPieShopDbContext.Categories;
var allPies = _context.Categories;

return View(allPies);
}
Expand All @@ -25,6 +27,33 @@ public IActionResult Create()
{
return View();
}

public IActionResult Detail(int? id)
{
var category = _context.Categories.Where(c => c.CategoryId == id).FirstOrDefault();

if (id == null || category == null)
{
return NotFound();
}
return View(category);
}

public async Task<IActionResult> Delete(int? id)
{
var category = await _context.Categories.FindAsync(id);

if (id != null || category != null)
{
_context.Categories.Remove(category);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));

}

return NotFound();

}
}
}

34 changes: 34 additions & 0 deletions Areas/Admin/Views/Category/Detail.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@model Category;


<div class="row justify-content-center">

<!-- Grow In Utility -->
<div class="col-lg-6">

<div class="card position-relative">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Category Title : <b>@Model.CategoryName</b></h6>
</div>
<div class="card-body">
<p>@Model.Description</p>
<p class="mb-2">Note: This utility animates the CSS transform property,
meaning it will override any existing transforms on an element being animated!
In this theme, the grow in animation is only being used on dropdowns within the
navbar.</p>
</div>
<div class="form-group row">
<div class="col-sm-6 mb-3 mb-sm-0">
<a asp-areas="Admin" asp-controller="Category" asp-action="Delete" asp-route-id="@Model.CategoryId"
class="form-control btn btn-danger">Delete</a>
</div>
<div class="col-sm-6 mb-3 mb-sm-0">
<a asp-areas="Admin" asp-controller="Category" asp-action="Index"
class="form-control btn btn-secondary">Back</a>
</div>
</div>
</div>

</div>

</div>
10 changes: 10 additions & 0 deletions Areas/Admin/Views/Category/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
<td>@category.CategoryId</td>
<td>@category.CategoryName</td>
<td>@category.Description</td>
<td>
<a asp-areas="Admin" asp-controller="Category" asp-action="Detail"
asp-route-id="@category.CategoryId" class="collapse-item">View
</a>
<a asp-areas="Admin" asp-controller="Pie" asp-action="Edit"
class="collapse-item">Edit</a>

<a asp-areas="Admin" asp-controller="Pie" asp-action="Edit" class="collapse-item">
Delete</a>
</td>
</tr>
}
</tbody>
Expand Down

0 comments on commit d5411bc

Please sign in to comment.