Skip to content

Commit 3028419

Browse files
committed
DetailsModel added
1 parent a2eed6f commit 3028419

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@page
2+
@model AspNetRunBasic.Pages.Product.DetailsModel
3+
@{
4+
ViewData["Title"] = "Details";
5+
}
6+
7+
<h1>Details</h1>
8+
9+
<div>
10+
<h4>Product</h4>
11+
<hr />
12+
<dl class="row">
13+
<dt class="col-sm-2">
14+
@Html.DisplayNameFor(model => model.Product.Name)
15+
</dt>
16+
<dd class="col-sm-10">
17+
@Html.DisplayFor(model => model.Product.Name)
18+
</dd>
19+
<dt class="col-sm-2">
20+
@Html.DisplayNameFor(model => model.Product.Description)
21+
</dt>
22+
<dd class="col-sm-10">
23+
@Html.DisplayFor(model => model.Product.Description)
24+
</dd>
25+
<dt class="col-sm-2">
26+
@Html.DisplayNameFor(model => model.Product.UnitPrice)
27+
</dt>
28+
<dd class="col-sm-10">
29+
@Html.DisplayFor(model => model.Product.UnitPrice)
30+
</dd>
31+
<dt class="col-sm-2">
32+
@Html.DisplayNameFor(model => model.Product.Category)
33+
</dt>
34+
<dd class="col-sm-10">
35+
@Html.DisplayFor(model => model.Product.Category.Name)
36+
</dd>
37+
</dl>
38+
</div>
39+
<div>
40+
<a asp-page="./Edit" asp-route-productId="@Model.Product.Id">Edit</a> |
41+
<a asp-page="./Index">Back to List</a>
42+
</div>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using AspNetRunBasic.Repositories;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.AspNetCore.Mvc.RazorPages;
8+
9+
namespace AspNetRunBasic.Pages.Product
10+
{
11+
public class DetailsModel : PageModel
12+
{
13+
private readonly IProductRepository _productRepository;
14+
15+
public DetailsModel(IProductRepository productRepository)
16+
{
17+
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
18+
}
19+
20+
public Entities.Product Product { get; set; }
21+
22+
public async Task<IActionResult> OnGetAsync(int? productId)
23+
{
24+
if (productId == null)
25+
{
26+
return NotFound();
27+
}
28+
29+
Product = await _productRepository.GetProductByIdAsync(productId.Value);
30+
if (Product == null)
31+
{
32+
return NotFound();
33+
}
34+
return Page();
35+
}
36+
37+
}
38+
}

0 commit comments

Comments
 (0)