Merge branch 'main' into tw-bootstrap
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
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Net.Mime;
|
||||
using Ardalis.ListStartupServices;
|
||||
using Azure.Identity;
|
||||
using BlazorAdmin;
|
||||
using BlazorAdmin.Services;
|
||||
using Blazored.LocalStorage;
|
||||
@@ -8,6 +9,7 @@ using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.eShopWeb;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
||||
using Microsoft.eShopWeb.Infrastructure.Data;
|
||||
@@ -18,10 +20,27 @@ using Microsoft.eShopWeb.Web.HealthChecks;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Logging.AddConsole();
|
||||
|
||||
Microsoft.eShopWeb.Infrastructure.Dependencies.ConfigureServices(builder.Configuration, builder.Services);
|
||||
if (builder.Environment.IsDevelopment() || builder.Environment.EnvironmentName == "Docker"){
|
||||
// Configure SQL Server (local)
|
||||
Microsoft.eShopWeb.Infrastructure.Dependencies.ConfigureServices(builder.Configuration, builder.Services);
|
||||
}
|
||||
else{
|
||||
// Configure SQL Server (prod)
|
||||
var credential = new ChainedTokenCredential(new AzureDeveloperCliCredential(), new DefaultAzureCredential());
|
||||
builder.Configuration.AddAzureKeyVault(new Uri(builder.Configuration["AZURE_KEY_VAULT_ENDPOINT"] ?? ""), credential);
|
||||
builder.Services.AddDbContext<CatalogContext>(c =>
|
||||
{
|
||||
var connectionString = builder.Configuration[builder.Configuration["AZURE_SQL_CATALOG_CONNECTION_STRING_KEY"] ?? ""];
|
||||
c.UseSqlServer(connectionString, sqlOptions => sqlOptions.EnableRetryOnFailure());
|
||||
});
|
||||
builder.Services.AddDbContext<AppIdentityDbContext>(options =>
|
||||
{
|
||||
var connectionString = builder.Configuration[builder.Configuration["AZURE_SQL_IDENTITY_CONNECTION_STRING_KEY"] ?? ""];
|
||||
options.UseSqlServer(connectionString, sqlOptions => sqlOptions.EnableRetryOnFailure());
|
||||
});
|
||||
}
|
||||
|
||||
builder.Services.AddCookieSettings();
|
||||
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
<PackageReference Include="Ardalis.ListStartupServices" />
|
||||
<PackageReference Include="Ardalis.Specification" />
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" />
|
||||
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" />
|
||||
<PackageReference Include="Azure.Identity" />
|
||||
<PackageReference Include="MediatR" />
|
||||
<PackageReference Include="BuildBundlerMinifier" Condition="'$(Configuration)'=='Release'" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" />
|
||||
|
||||
@@ -17,4 +17,4 @@
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user