Order items in ordering api
This commit is contained in:
parent
373946b5c6
commit
9e72fe7c7c
@ -15,8 +15,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
||||
var host = new WebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseUrls("http://0.0.0.0:5103")
|
||||
//.UseIISIntegration()
|
||||
.UseUrls("http://0.0.0.0:5003")
|
||||
.UseIISIntegration()
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:2160/",
|
||||
"applicationUrl": "http://localhost:5003/",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
|
@ -7,6 +7,6 @@
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
},
|
||||
"IdentityUrl": "http://localhost:5105",
|
||||
"IdentityUrl": "http://localhost:5000",
|
||||
"ConnectionString": "127.0.0.1"
|
||||
}
|
||||
|
@ -56,29 +56,29 @@
|
||||
var user =
|
||||
new ApplicationUser()
|
||||
{
|
||||
CardHolderName = "Jhon Doe",
|
||||
CardNumber = "1111-2222-33-4444",
|
||||
CardHolderName = "DemoUser",
|
||||
CardNumber = "4012888888881881",
|
||||
CardType = 1,
|
||||
City = "Seattle",
|
||||
Country = "EEUU",
|
||||
City = "Redmond",
|
||||
Country = "U.S.",
|
||||
CountryCode = "91",
|
||||
Email = "jdoe@eshop.com",
|
||||
Email = "demouser@microsoft.com",
|
||||
Expiration = "12/20",
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
LastName = "Doe",
|
||||
Name = "Jhon",
|
||||
PhoneNumber = "600 11 22 33",
|
||||
UserName = "jdoe@eshop.com",
|
||||
ZipCode = "56730",
|
||||
State = "Washington",
|
||||
Street = "Street..",
|
||||
SecurityNumber = "256",
|
||||
NormalizedEmail = "JDOE@ESHOP.COM",
|
||||
NormalizedUserName = "JDOE@ESHOP.COM",
|
||||
LastName = "DemoLastName",
|
||||
Name = "DemoUser",
|
||||
PhoneNumber = "1234567890",
|
||||
UserName = "demouser@microsoft.com",
|
||||
ZipCode = "98052",
|
||||
State = "WA",
|
||||
Street = "15703 NE 61st Ct",
|
||||
SecurityNumber = "535",
|
||||
NormalizedEmail = "DEMOUSER@MICROSOFT.COM",
|
||||
NormalizedUserName = "DEMOUSER@MICROSOFT.COM",
|
||||
SecurityStamp = Guid.NewGuid().ToString("D")
|
||||
};
|
||||
|
||||
user.PasswordHash = _passwordHasher.HashPassword(user, "eshopContainers.123");
|
||||
user.PasswordHash = _passwordHasher.HashPassword(user, "Pass@word1");
|
||||
|
||||
return user;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace eShopOnContainers.Identity
|
||||
{
|
||||
var host = new WebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseUrls("http://0.0.0.0:5105")
|
||||
.UseUrls("http://0.0.0.0:5000")
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseIISIntegration()
|
||||
.UseStartup<Startup>()
|
||||
|
@ -53,6 +53,17 @@
|
||||
Street = order.ShippingStreet
|
||||
};
|
||||
|
||||
foreach (var orderItem in order.Items)
|
||||
{
|
||||
newOrderRequest.AddOrderItem(new Domain.OrderItem() {
|
||||
Discount = orderItem.Discount,
|
||||
ProductId = orderItem.ProductId,
|
||||
UnitPrice = orderItem.UnitPrice,
|
||||
ProductName = orderItem.ProductName,
|
||||
Units = orderItem.Units
|
||||
});
|
||||
}
|
||||
|
||||
var added = await _mediator.SendAsync(newOrderRequest);
|
||||
|
||||
if (added)
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Models
|
||||
{
|
||||
@ -21,5 +22,12 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Models
|
||||
public DateTime CardExpiration { get; set; }
|
||||
|
||||
public string CardSecurityNumber { get; set; }
|
||||
|
||||
public List<OrderItemViewModel> Items { get; set; }
|
||||
|
||||
public NewOrderViewModel()
|
||||
{
|
||||
Items = new List<OrderItemViewModel>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Models
|
||||
{
|
||||
public class OrderItemViewModel
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
|
||||
public string ProductName { get; set; }
|
||||
|
||||
public decimal UnitPrice { get; set; }
|
||||
|
||||
public decimal Discount { get; set; }
|
||||
|
||||
public int Units { get; set; }
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:5102/",
|
||||
"applicationUrl": "http://localhost:5002/",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
|
@ -55,6 +55,11 @@
|
||||
ZipCode = message.ZipCode
|
||||
});
|
||||
|
||||
foreach (var item in message.OrderItems)
|
||||
{
|
||||
order.AddOrderItem(item);
|
||||
}
|
||||
|
||||
_orderRepository.Add(order);
|
||||
|
||||
var result = await _orderRepository.UnitOfWork
|
||||
|
@ -2,10 +2,15 @@
|
||||
{
|
||||
using System;
|
||||
using MediatR;
|
||||
using Domain;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class NewOrderRequest
|
||||
:IAsyncRequest<bool>
|
||||
{
|
||||
|
||||
private readonly List<OrderItem> _orderItems;
|
||||
public string City { get; set; }
|
||||
|
||||
public string Street { get; set; }
|
||||
@ -27,5 +32,17 @@
|
||||
public int CardTypeId { get; set; }
|
||||
|
||||
public string Buyer { get; set; }
|
||||
|
||||
public IEnumerable<OrderItem> OrderItems => _orderItems;
|
||||
|
||||
public void AddOrderItem(OrderItem item)
|
||||
{
|
||||
_orderItems.Add(item);
|
||||
}
|
||||
|
||||
public NewOrderRequest()
|
||||
{
|
||||
_orderItems = new List<OrderItem>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
public OrderStatus Status { get; private set; }
|
||||
|
||||
public ICollection<OrderItem> OrderItems { get; set; }
|
||||
public ICollection<OrderItem> OrderItems { get; private set; }
|
||||
|
||||
public int? ShippingAddressId { get; private set; }
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
PaymentId = paymentId;
|
||||
StatusId = OrderStatus.InProcess.Id;
|
||||
OrderDate = DateTime.UtcNow;
|
||||
OrderItems = new List<OrderItem>();
|
||||
}
|
||||
|
||||
public void SetAddress(Address address)
|
||||
@ -46,5 +47,12 @@
|
||||
|
||||
ShippingAddress = address;
|
||||
}
|
||||
|
||||
public void AddOrderItem(OrderItem item)
|
||||
{
|
||||
// Note: Some logic could be added here (like grouping items in one single OrderItem)
|
||||
// Also validation logic could be added here (like ensuring adding almost one item)
|
||||
OrderItems.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,20 +6,17 @@
|
||||
public class OrderItem
|
||||
:Entity
|
||||
{
|
||||
public int ProductId { get; private set; }
|
||||
public int ProductId { get; set; }
|
||||
|
||||
public string ProductName { get; private set; }
|
||||
public string ProductName { get; set; }
|
||||
|
||||
public int OrderId { get; private set; }
|
||||
public int OrderId { get; set; }
|
||||
|
||||
public decimal UnitPrice { get; private set; }
|
||||
public decimal UnitPrice { get; set; }
|
||||
|
||||
public decimal Discount { get; private set; }
|
||||
public decimal Discount { get; set; }
|
||||
|
||||
public int Units { get; private set; }
|
||||
public int Units { get; set; }
|
||||
|
||||
protected OrderItem()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
|
||||
{
|
||||
HttpContext.Authentication.SignOutAsync("Cookies");
|
||||
HttpContext.Authentication.SignOutAsync("oidc");
|
||||
|
||||
return new SignOutResult("oidc", new AuthenticationProperties { RedirectUri = "/" });
|
||||
}
|
||||
}
|
||||
|
@ -42,11 +42,13 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
|
||||
basket = await _basketSvc.UpdateBasket(basket);
|
||||
var order = _basketSvc.MapBasketToOrder(basket);
|
||||
|
||||
|
||||
// override if user has changed some shipping address or payment info data.
|
||||
_orderSvc.OverrideUserInfoIntoOrder(model.Order, order);
|
||||
|
||||
if (action == "[ Place Order ]")
|
||||
{
|
||||
|
||||
await _orderSvc.CreateOrder(user, order);
|
||||
|
||||
//Empty basket for current user.
|
||||
|
@ -8,7 +8,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Models
|
||||
public class OrderRequest
|
||||
{
|
||||
public OrderRequest() {
|
||||
|
||||
Items = new List<OrderRequestItem>();
|
||||
}
|
||||
|
||||
public string City { get; set; }
|
||||
@ -32,5 +32,9 @@ namespace Microsoft.eShopOnContainers.WebMVC.Models
|
||||
public int CardTypeId { get; set; }
|
||||
|
||||
public string Buyer { get; set; }
|
||||
|
||||
public List<OrderRequestItem> Items { get; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
20
src/Web/WebMVC/Models/OrderRequestItem.cs
Normal file
20
src/Web/WebMVC/Models/OrderRequestItem.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.WebMVC.Models
|
||||
{
|
||||
public class OrderRequestItem
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
|
||||
public string ProductName { get; set; }
|
||||
|
||||
public decimal UnitPrice { get; set; }
|
||||
|
||||
public decimal Discount { get; set; }
|
||||
|
||||
public int Units { get; set; }
|
||||
}
|
||||
}
|
@ -111,7 +111,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
|
||||
|
||||
public OrderRequest MapOrderIntoOrderRequest(Order order)
|
||||
{
|
||||
return new OrderRequest()
|
||||
var od = new OrderRequest()
|
||||
{
|
||||
CardHolderName = order.PaymentInfo.CardHolderName,
|
||||
CardNumber = order.PaymentInfo.CardNumber,
|
||||
@ -121,8 +121,22 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
|
||||
Country = order.ShippingAddress.Country,
|
||||
State = order.ShippingAddress.State,
|
||||
Street = order.ShippingAddress.Street,
|
||||
ZipCode = order.ShippingAddress.ZipCode
|
||||
ZipCode = order.ShippingAddress.ZipCode,
|
||||
};
|
||||
|
||||
foreach (var item in order.OrderItems)
|
||||
{
|
||||
od.Items.Add(new OrderRequestItem()
|
||||
{
|
||||
Discount = item.Discount,
|
||||
ProductId = int.Parse(item.ProductId),
|
||||
ProductName = item.ProductName,
|
||||
UnitPrice = item.UnitPrice,
|
||||
Units = item.Quantity
|
||||
});
|
||||
}
|
||||
|
||||
return od;
|
||||
}
|
||||
|
||||
async public Task CreateOrder(ApplicationUser user, Order order)
|
||||
|
@ -2,7 +2,7 @@
|
||||
"CatalogUrl": "http://localhost:5101",
|
||||
"OrderingUrl": "http://localhost:5102",
|
||||
"BasketUrl": "http://localhost:5103",
|
||||
"IdentityUrl": "http://localhost:5000",
|
||||
"IdentityUrl": "http://localhost:5105",
|
||||
"CallBackUrl": "http://localhost:5100/",
|
||||
"Logging": {
|
||||
"IncludeScopes": false,
|
||||
|
Loading…
x
Reference in New Issue
Block a user