Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ca9e409

Browse filesBrowse files
committed
order page implemented
1 parent ee5994b commit ca9e409
Copy full SHA for ca9e409

File tree

Expand file treeCollapse file tree

10 files changed

+94
-19
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+94
-19
lines changed

‎AspnetRunBasics/Pages/Cart.cshtml.cs

Copy file name to clipboardExpand all lines: AspnetRunBasics/Pages/Cart.cshtml.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ public async Task<IActionResult> OnPostRemoveToCartAsync(int cartId, int cartIte
2929
{
3030
await _cartRepository.RemoveItem(cartId, cartItemId);
3131
return RedirectToPage();
32-
}
32+
}
3333
}
3434
}

‎AspnetRunBasics/Pages/Index.cshtml.cs

Copy file name to clipboardExpand all lines: AspnetRunBasics/Pages/Index.cshtml.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public IndexModel(IProductRepository productRepository, ICartRepository cartRepo
2222

2323
public async Task<IActionResult> OnGetAsync()
2424
{
25-
ProductList = await _productRepository.GetProductListAsync();
25+
ProductList = await _productRepository.GetProducts();
2626
return Page();
2727
}
2828

‎AspnetRunBasics/Pages/Order.cshtml

Copy file name to clipboardExpand all lines: AspnetRunBasics/Pages/Order.cshtml
+53-1Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,57 @@
44
ViewData["Title"] = "Order";
55
}
66

7-
<h1>Order</h1>
7+
<div class="container">
8+
<div class="row">
9+
<div class="col">
10+
<nav aria-label="breadcrumb">
11+
<ol class="breadcrumb">
12+
<li class="breadcrumb-item"><a asp-page="Index">Home</a></li>
13+
<li class="breadcrumb-item active" aria-current="page">Order</li>
14+
</ol>
15+
</nav>
16+
</div>
17+
</div>
18+
</div>
819

20+
<div class="container mb-4">
21+
<div class="row">
22+
<div class="col-12">
23+
<div class="table-responsive">
24+
<table class="table table-striped">
25+
<thead>
26+
<tr>
27+
<th scope="col"> </th>
28+
<th scope="col">First Name</th>
29+
<th scope="col">Last Name</th>
30+
<th scope="col">Email</th>
31+
<th scope="col">Address</th>
32+
<th scope="col" class="text-right">TotalPrice</th>
33+
</tr>
34+
</thead>
35+
<tbody>
36+
37+
@foreach (var order in Model.Orders)
38+
{
39+
<tr>
40+
<td><img src="https://dummyimage.com/50x50/55595c/fff" /></td>
41+
<td>@order.FirstName</td>
42+
<td>@order.LastName</td>
43+
<td>@order.EmailAddress</td>
44+
<td>@order.AddressLine</td>
45+
<td class="text-right">@order.TotalPrice $</td>
46+
</tr>
47+
}
48+
</tbody>
49+
</table>
50+
</div>
51+
</div>
52+
<div class="col mb-2">
53+
<div class="row">
54+
<div class="col-sm-12 col-md-6">
55+
<a asp-page="Product" class="btn btn-lg btn-block btn-success">Continue Shopping</a>
56+
</div>
57+
</div>
58+
</div>
59+
</div>
60+
</div>

‎AspnetRunBasics/Pages/Order.cshtml.cs

Copy file name to clipboard
+14-3Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using System.Threading.Tasks;
4+
using AspnetRunBasics.Repositories;
55
using Microsoft.AspNetCore.Mvc;
66
using Microsoft.AspNetCore.Mvc.RazorPages;
77

88
namespace AspnetRunBasics
99
{
1010
public class OrderModel : PageModel
1111
{
12-
public void OnGet()
13-
{
12+
private readonly IOrderRepository _orderRepository;
1413

14+
public OrderModel(IOrderRepository orderRepository)
15+
{
16+
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
1517
}
18+
19+
public IEnumerable<Entities.Order> Orders { get; set; } = new List<Entities.Order>();
20+
21+
public async Task<IActionResult> OnGetAsync()
22+
{
23+
Orders = await _orderRepository.GetOrdersByUserName("test");
24+
25+
return Page();
26+
}
1627
}
1728
}

‎AspnetRunBasics/Pages/Product.cshtml.cs

Copy file name to clipboardExpand all lines: AspnetRunBasics/Pages/Product.cshtml.cs
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ public async Task<IActionResult> OnGetAsync(int? categoryId)
3232

3333
if (categoryId.HasValue)
3434
{
35-
ProductList = await _productRepository.GetProductByCategoryAsync(categoryId.Value);
35+
ProductList = await _productRepository.GetProductByCategory(categoryId.Value);
3636
SelectedCategory = CategoryList.FirstOrDefault(c => c.Id == categoryId.Value)?.Name;
3737
}
3838
else
3939
{
40-
ProductList = await _productRepository.GetProductListAsync();
40+
ProductList = await _productRepository.GetProducts();
4141
}
4242

4343
return Page();

‎AspnetRunBasics/Pages/ProductDetail.cshtml.cs

Copy file name to clipboardExpand all lines: AspnetRunBasics/Pages/ProductDetail.cshtml.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public async Task<IActionResult> OnGetAsync(int? productId)
3232
return NotFound();
3333
}
3434

35-
Product = await _productRepository.GetProductByIdAsync(productId.Value);
35+
Product = await _productRepository.GetProductById(productId.Value);
3636
if (Product == null)
3737
{
3838
return NotFound();
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using AspnetRunBasics.Entities;
2+
using System.Collections.Generic;
23
using System.Threading.Tasks;
34

45
namespace AspnetRunBasics.Repositories
56
{
67
public interface IOrderRepository
78
{
89
Task<Order> CheckOut(Order order);
10+
Task<IEnumerable<Order>> GetOrdersByUserName(string userName);
911
}
1012
}
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
using AspnetRunBasics.Entities;
2-
using System;
32
using System.Collections.Generic;
4-
using System.Linq;
53
using System.Threading.Tasks;
64

75
namespace AspnetRunBasics.Repositories
86
{
97
public interface IProductRepository
108
{
11-
Task<IEnumerable<Product>> GetProductListAsync();
12-
Task<Product> GetProductByIdAsync(int id);
13-
Task<IEnumerable<Product>> GetProductByNameAsync(string name);
14-
Task<IEnumerable<Product>> GetProductByCategoryAsync(int categoryId);
9+
Task<IEnumerable<Product>> GetProducts();
10+
Task<Product> GetProductById(int id);
11+
Task<IEnumerable<Product>> GetProductByName(string name);
12+
Task<IEnumerable<Product>> GetProductByCategory(int categoryId);
1513
Task<IEnumerable<Category>> GetCategories();
1614
}
1715
}

‎AspnetRunBasics/Repositories/OrderRepository.cs

Copy file name to clipboardExpand all lines: AspnetRunBasics/Repositories/OrderRepository.cs
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using AspnetRunBasics.Data;
22
using AspnetRunBasics.Entities;
3+
using Microsoft.EntityFrameworkCore;
34
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
47
using System.Threading.Tasks;
58

69
namespace AspnetRunBasics.Repositories
@@ -20,5 +23,14 @@ public async Task<Order> CheckOut(Order order)
2023
await _dbContext.SaveChangesAsync();
2124
return order;
2225
}
26+
27+
public async Task<IEnumerable<Order>> GetOrdersByUserName(string userName)
28+
{
29+
var orderList = await _dbContext.Orders
30+
.Where(o => o.UserName == userName)
31+
.ToListAsync();
32+
33+
return orderList;
34+
}
2335
}
2436
}

‎AspnetRunBasics/Repositories/ProductRepository.cs

Copy file name to clipboardExpand all lines: AspnetRunBasics/Repositories/ProductRepository.cs
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ public ProductRepository(AspnetRunContext dbContext)
1717
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
1818
}
1919

20-
public async Task<IEnumerable<Product>> GetProductListAsync()
20+
public async Task<IEnumerable<Product>> GetProducts()
2121
{
2222
return await _dbContext.Products.ToListAsync();
2323
}
2424

25-
public async Task<Product> GetProductByIdAsync(int id)
25+
public async Task<Product> GetProductById(int id)
2626
{
2727
return await _dbContext.Products
2828
.Include(p => p.Category)
2929
.FirstOrDefaultAsync(p => p.Id == id);
3030
}
3131

32-
public async Task<IEnumerable<Product>> GetProductByNameAsync(string name)
32+
public async Task<IEnumerable<Product>> GetProductByName(string name)
3333
{
3434
return await _dbContext.Products
3535
.Include(p => p.Category)
@@ -38,7 +38,7 @@ public async Task<IEnumerable<Product>> GetProductByNameAsync(string name)
3838
.ToListAsync();
3939
}
4040

41-
public async Task<IEnumerable<Product>> GetProductByCategoryAsync(int categoryId)
41+
public async Task<IEnumerable<Product>> GetProductByCategory(int categoryId)
4242
{
4343
return await _dbContext.Products
4444
.Where(x => x.CategoryId == categoryId)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.