Skip to content

Commit 576746b

Browse files
committed
product part fixed
1 parent 949f041 commit 576746b

File tree

6 files changed

+61
-121
lines changed

6 files changed

+61
-121
lines changed

AspNetRunBasicRealWorld/Entities/Product.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class Product
1212
public string Summary { get; set; }
1313
public string Description { get; set; }
1414
public string ImageFile { get; set; }
15-
public int UnitPrice { get; set; }
15+
public int Price { get; set; }
1616
public int CategoryId { get; set; }
1717
public Category Category { get; set; }
1818
}

AspNetRunBasicRealWorld/Pages/Category.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
</div>
2424
</div>
2525
}
26-
</div>
26+
</div>
2727
<hr />
28+
<hr class="mb-5" />
2829
<div class="row">
2930
<div class="col-md-4">
3031
<partial name="_MobileWidgetPartial" model="@("Download Today")" />

AspNetRunBasicRealWorld/Pages/Index.cshtml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,22 @@
5656
{
5757
<div class="col-lg-4 col-sm-6 portfolio-item">
5858
<div class="card h-100">
59-
<a asp-page="Product" asp-route-productId="@product.Id"><img asp-append-version="true" class="card-img-top" src="~/images/product/@product.ImageFile" alt=""></a>
59+
<a asp-page="ProductDetail" asp-route-productId="@product.Id"><img asp-append-version="true" class="card-img-top" src="~/images/product/@product.ImageFile" alt=""></a>
6060
<div class="card-body">
6161
<h4 class="card-title">
62-
<a asp-page="Product" asp-route-productId="@product.Id" class="color-main">@product.Name</a>
62+
<a asp-page="ProductDetail" asp-route-productId="@product.Id" class="color-main">@product.Name</a>
6363
</h4>
6464
<p class="card-text">@product.Summary</p>
6565
</div>
6666
<div class="card-footer">
67-
<a asp-page="Product" asp-route-productId="@product.Id" class="btn btn-success w-100">Add to Cart</a>
67+
<div class="row">
68+
<div class="col">
69+
<p class="btn btn-danger">@product.Price</p>
70+
</div>
71+
<div class="col">
72+
<a asp-page="ProductDetail" asp-route-productId="@product.Id" class="btn btn-success btn-block">Add to Cart</a>
73+
</div>
74+
</div>
6875
</div>
6976
</div>
7077
</div>

AspNetRunBasicRealWorld/Pages/Product.cshtml

Lines changed: 30 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -11,127 +11,42 @@
1111
<div class="card bg-light mb-3">
1212
<div class="card-header bg-primary text-white text-uppercase"><i class="fa fa-list"></i> Categories</div>
1313
<ul class="list-group category_block">
14-
<li class="list-group-item"><a href="category.html">Cras justo odio</a></li>
15-
<li class="list-group-item"><a href="category.html">Dapibus ac facilisis in</a></li>
16-
<li class="list-group-item"><a href="category.html">Morbi leo risus</a></li>
17-
<li class="list-group-item"><a href="category.html">Porta ac consectetur ac</a></li>
18-
<li class="list-group-item"><a href="category.html">Vestibulum at eros</a></li>
14+
@foreach (var category in Model.CategoryList)
15+
{
16+
<li class="list-group-item"><a asp-page="Product" asp-route-categoryId="@category.Id">@category.Name</a></li>
17+
}
1918
</ul>
20-
</div>
21-
<div class="card bg-light mb-3">
22-
<div class="card-header bg-success text-white text-uppercase">Last product</div>
23-
<div class="card-body">
24-
<img class="img-fluid" src="https://dummyimage.com/600x400/55595c/fff" />
25-
<h5 class="card-title">Product title</h5>
26-
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
27-
<p class="bloc_left_price">99.00 $</p>
28-
</div>
29-
</div>
19+
</div>
3020
</div>
3121
<div class="col">
3222
<div class="row">
33-
<div class="col-12 col-md-6 col-lg-4">
34-
<div class="card">
35-
<img class="card-img-top" src="https://dummyimage.com/600x400/55595c/fff" alt="Card image cap">
36-
<div class="card-body">
37-
<h4 class="card-title"><a href="product.html" title="View Product">Product title</a></h4>
38-
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
39-
<div class="row">
40-
<div class="col">
41-
<p class="btn btn-danger btn-block">99.00 $</p>
42-
</div>
43-
<div class="col">
44-
<a href="#" class="btn btn-success btn-block">Add to cart</a>
45-
</div>
46-
</div>
47-
</div>
48-
</div>
49-
</div>
50-
<div class="col-12 col-md-6 col-lg-4">
51-
<div class="card">
52-
<img class="card-img-top" src="https://dummyimage.com/600x400/55595c/fff" alt="Card image cap">
53-
<div class="card-body">
54-
<h4 class="card-title"><a href="product.html" title="View Product">Product title</a></h4>
55-
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
56-
<div class="row">
57-
<div class="col">
58-
<p class="btn btn-danger btn-block">99.00 $</p>
59-
</div>
60-
<div class="col">
61-
<a href="#" class="btn btn-success btn-block">Add to cart</a>
62-
</div>
63-
</div>
64-
</div>
65-
</div>
66-
</div>
67-
<div class="col-12 col-md-6 col-lg-4">
68-
<div class="card">
69-
<img class="card-img-top" src="https://dummyimage.com/600x400/55595c/fff" alt="Card image cap">
70-
<div class="card-body">
71-
<h4 class="card-title"><a href="product.html" title="View Product">Product title</a></h4>
72-
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
73-
<div class="row">
74-
<div class="col">
75-
<p class="btn btn-danger btn-block">99.00 $</p>
76-
</div>
77-
<div class="col">
78-
<a href="#" class="btn btn-success btn-block">Add to cart</a>
79-
</div>
80-
</div>
81-
</div>
82-
</div>
83-
</div>
84-
<div class="col-12 col-md-6 col-lg-4">
85-
<div class="card">
86-
<img class="card-img-top" src="https://dummyimage.com/600x400/55595c/fff" alt="Card image cap">
87-
<div class="card-body">
88-
<h4 class="card-title"><a href="product.html" title="View Product">Product title</a></h4>
89-
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
90-
<div class="row">
91-
<div class="col">
92-
<p class="btn btn-danger btn-block">99.00 $</p>
93-
</div>
94-
<div class="col">
95-
<a href="#" class="btn btn-success btn-block">Add to cart</a>
96-
</div>
97-
</div>
98-
</div>
99-
</div>
100-
</div>
101-
<div class="col-12 col-md-6 col-lg-4">
102-
<div class="card">
103-
<img class="card-img-top" src="https://dummyimage.com/600x400/55595c/fff" alt="Card image cap">
104-
<div class="card-body">
105-
<h4 class="card-title"><a href="product.html" title="View Product">Product title</a></h4>
106-
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
107-
<div class="row">
108-
<div class="col">
109-
<p class="btn btn-danger btn-block">99.00 $</p>
110-
</div>
111-
<div class="col">
112-
<a href="#" class="btn btn-success btn-block">Add to cart</a>
113-
</div>
114-
</div>
115-
</div>
116-
</div>
117-
</div>
118-
<div class="col-12 col-md-6 col-lg-4">
119-
<div class="card">
120-
<img class="card-img-top" src="https://dummyimage.com/600x400/55595c/fff" alt="Card image cap">
121-
<div class="card-body">
122-
<h4 class="card-title"><a href="product.html" title="View Product">Product title</a></h4>
123-
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
124-
<div class="row">
125-
<div class="col">
126-
<p class="btn btn-danger btn-block">99.00 $</p>
127-
</div>
128-
<div class="col">
129-
<a href="#" class="btn btn-success btn-block">Add to cart</a>
23+
24+
@foreach (var product in Model.ProductList)
25+
{
26+
<div class="col-12 col-md-6 col-lg-4">
27+
<div class="card">
28+
<a asp-page="ProductDetail" asp-route-productId="@product.Id"><img asp-append-version="true" class="card-img-top" src="~/images/product/@product.ImageFile" alt=""></a>
29+
<div class="card-body">
30+
<h4 class="card-title">
31+
<a asp-page="ProductDetail" asp-route-productId="@product.Id" class="color-main">@product.Name</a>
32+
</h4>
33+
<p class="card-text">@product.Summary</p>
34+
<div class="card-footer">
35+
<div class="row">
36+
<div class="col">
37+
<p class="btn btn-danger">@product.Price</p>
38+
</div>
39+
<div class="col">
40+
<a asp-page="Product" asp-route-productId="@product.Id" class="btn btn-success btn-block">Add to Cart</a>
41+
</div>
42+
</div>
13043
</div>
13144
</div>
13245
</div>
13346
</div>
134-
</div>
47+
}
48+
49+
13550
<div class="col-12">
13651
<nav aria-label="...">
13752
<ul class="pagination">
@@ -149,6 +64,8 @@
14964
</ul>
15065
</nav>
15166
</div>
67+
68+
15269
</div>
15370
</div>
15471

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using System.Threading.Tasks;
4+
using AspNetRunBasicRealWorld.Repositories;
55
using Microsoft.AspNetCore.Mvc;
66
using Microsoft.AspNetCore.Mvc.RazorPages;
77

88
namespace AspNetRunBasicRealWorld
99
{
1010
public class ProductModel : PageModel
1111
{
12-
public void OnGet()
12+
private readonly IProductRepository _productRepository;
13+
14+
public ProductModel(IProductRepository productRepository)
15+
{
16+
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
17+
}
18+
19+
public IEnumerable<Entities.Category> CategoryList { get; set; } = new List<Entities.Category>();
20+
public IEnumerable<Entities.Product> ProductList { get; set; } = new List<Entities.Product>();
21+
22+
public async Task<IActionResult> OnGetAsync(int? categoryId)
1323
{
24+
CategoryList = await _productRepository.GetCategories();
25+
ProductList = await _productRepository.GetProductByNameAsync(string.Empty);
26+
// ProductList = await _productRepository.GetProductByCategoryIdAsync(categoryId.Value);
1427

28+
return Page();
29+
1530
}
1631
}
1732
}

AspNetRunBasicRealWorld/Pages/ProductDetail.cshtml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ public async Task<IActionResult> OnGetAsync(int? productId)
3030
return NotFound();
3131
}
3232
return Page();
33-
}
33+
}
3434
}
3535
}

0 commit comments

Comments
 (0)