Merge remote-tracking branch 'upstream/main'
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using Ardalis.Specification;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
|
||||
|
||||
namespace Microsoft.eShopWeb.ApplicationCore.Specifications;
|
||||
|
||||
public class CustomerOrdersSpecification : Specification<Order>
|
||||
{
|
||||
public CustomerOrdersSpecification(string buyerId)
|
||||
{
|
||||
Query.Where(o => o.BuyerId == buyerId)
|
||||
.Include(o => o.OrderItems);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"CatalogConnection": "Server=sqlserver,1433;Integrated Security=true;Initial Catalog=Microsoft.eShopOnWeb.CatalogDb;User Id=sa;Password=@someThingComplicated1234;Trusted_Connection=false;",
|
||||
"IdentityConnection": "Server=sqlserver,1433;Integrated Security=true;Initial Catalog=Microsoft.eShopOnWeb.Identity;User Id=sa;Password=@someThingComplicated1234;Trusted_Connection=false;"
|
||||
"CatalogConnection": "Server=sqlserver,1433;Integrated Security=true;Initial Catalog=Microsoft.eShopOnWeb.CatalogDb;User Id=sa;Password=@someThingComplicated1234;Trusted_Connection=false;TrustServerCertificate=true;",
|
||||
"IdentityConnection": "Server=sqlserver,1433;Integrated Security=true;Initial Catalog=Microsoft.eShopOnWeb.Identity;User Id=sa;Password=@someThingComplicated1234;Trusted_Connection=false;TrustServerCertificate=true;"
|
||||
},
|
||||
"baseUrls": {
|
||||
"apiBase": "http://localhost:5200/api/",
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using MediatR;
|
||||
using MediatR;
|
||||
using Microsoft.eShopWeb.Web.ViewModels;
|
||||
|
||||
namespace Microsoft.eShopWeb.Web.Features.MyOrders;
|
||||
|
||||
@@ -18,20 +18,12 @@ public class GetMyOrdersHandler : IRequestHandler<GetMyOrders, IEnumerable<Order
|
||||
public async Task<IEnumerable<OrderViewModel>> Handle(GetMyOrders request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var specification = new CustomerOrdersWithItemsSpecification(request.UserName);
|
||||
var specification = new CustomerOrdersSpecification(request.UserName);
|
||||
var orders = await _orderRepository.ListAsync(specification, cancellationToken);
|
||||
|
||||
return orders.Select(o => new OrderViewModel
|
||||
{
|
||||
OrderDate = o.OrderDate,
|
||||
OrderItems = o.OrderItems.Select(oi => new OrderItemViewModel()
|
||||
{
|
||||
PictureUrl = oi.ItemOrdered.PictureUri,
|
||||
ProductId = oi.ItemOrdered.CatalogItemId,
|
||||
ProductName = oi.ItemOrdered.ProductName,
|
||||
UnitPrice = oi.UnitPrice,
|
||||
Units = oi.Units
|
||||
}).ToList(),
|
||||
OrderNumber = o.Id,
|
||||
ShippingAddress = o.ShipToAddress,
|
||||
Total = o.Total()
|
||||
|
||||
@@ -3,7 +3,7 @@ using Microsoft.eShopWeb.Web.ViewModels;
|
||||
|
||||
namespace Microsoft.eShopWeb.Web.Features.OrderDetails;
|
||||
|
||||
public class GetOrderDetails : IRequest<OrderViewModel>
|
||||
public class GetOrderDetails : IRequest<OrderDetailViewModel>
|
||||
{
|
||||
public string UserName { get; set; }
|
||||
public int OrderId { get; set; }
|
||||
|
||||
@@ -6,7 +6,7 @@ using Microsoft.eShopWeb.Web.ViewModels;
|
||||
|
||||
namespace Microsoft.eShopWeb.Web.Features.OrderDetails;
|
||||
|
||||
public class GetOrderDetailsHandler : IRequestHandler<GetOrderDetails, OrderViewModel?>
|
||||
public class GetOrderDetailsHandler : IRequestHandler<GetOrderDetails, OrderDetailViewModel?>
|
||||
{
|
||||
private readonly IReadRepository<Order> _orderRepository;
|
||||
|
||||
@@ -15,7 +15,7 @@ public class GetOrderDetailsHandler : IRequestHandler<GetOrderDetails, OrderView
|
||||
_orderRepository = orderRepository;
|
||||
}
|
||||
|
||||
public async Task<OrderViewModel?> Handle(GetOrderDetails request,
|
||||
public async Task<OrderDetailViewModel?> Handle(GetOrderDetails request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var spec = new OrderWithItemsByIdSpec(request.OrderId);
|
||||
@@ -26,7 +26,7 @@ public class GetOrderDetailsHandler : IRequestHandler<GetOrderDetails, OrderView
|
||||
return null;
|
||||
}
|
||||
|
||||
return new OrderViewModel
|
||||
return new OrderDetailViewModel
|
||||
{
|
||||
OrderDate = order.OrderDate,
|
||||
OrderItems = order.OrderItems.Select(oi => new OrderItemViewModel
|
||||
|
||||
6
src/Web/ViewModels/OrderDetailViewModel.cs
Normal file
6
src/Web/ViewModels/OrderDetailViewModel.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Microsoft.eShopWeb.Web.ViewModels;
|
||||
|
||||
public class OrderDetailViewModel : OrderViewModel
|
||||
{
|
||||
public List<OrderItemViewModel> OrderItems { get; set; } = new();
|
||||
}
|
||||
@@ -11,5 +11,4 @@ public class OrderViewModel
|
||||
public decimal Total { get; set; }
|
||||
public string Status => DEFAULT_STATUS;
|
||||
public Address? ShippingAddress { get; set; }
|
||||
public List<OrderItemViewModel> OrderItems { get; set; } = new();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@model OrderViewModel
|
||||
@model OrderDetailViewModel
|
||||
@{
|
||||
ViewData["Title"] = "My Order History";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user