Order items in ordering api

This commit is contained in:
Carlos Cañizares Estévez 2016-12-14 18:23:57 +01:00
parent 373946b5c6
commit 9e72fe7c7c
19 changed files with 138 additions and 36 deletions

View File

@ -15,8 +15,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
var host = new WebHostBuilder() var host = new WebHostBuilder()
.UseKestrel() .UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory()) .UseContentRoot(Directory.GetCurrentDirectory())
.UseUrls("http://0.0.0.0:5103") .UseUrls("http://0.0.0.0:5003")
//.UseIISIntegration() .UseIISIntegration()
.UseStartup<Startup>() .UseStartup<Startup>()
.Build(); .Build();

View File

@ -3,7 +3,7 @@
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:2160/", "applicationUrl": "http://localhost:5003/",
"sslPort": 0 "sslPort": 0
} }
}, },

View File

@ -7,6 +7,6 @@
"Microsoft": "Information" "Microsoft": "Information"
} }
}, },
"IdentityUrl": "http://localhost:5105", "IdentityUrl": "http://localhost:5000",
"ConnectionString": "127.0.0.1" "ConnectionString": "127.0.0.1"
} }

View File

@ -56,29 +56,29 @@
var user = var user =
new ApplicationUser() new ApplicationUser()
{ {
CardHolderName = "Jhon Doe", CardHolderName = "DemoUser",
CardNumber = "1111-2222-33-4444", CardNumber = "4012888888881881",
CardType = 1, CardType = 1,
City = "Seattle", City = "Redmond",
Country = "EEUU", Country = "U.S.",
CountryCode = "91", CountryCode = "91",
Email = "jdoe@eshop.com", Email = "demouser@microsoft.com",
Expiration = "12/20", Expiration = "12/20",
Id = Guid.NewGuid().ToString(), Id = Guid.NewGuid().ToString(),
LastName = "Doe", LastName = "DemoLastName",
Name = "Jhon", Name = "DemoUser",
PhoneNumber = "600 11 22 33", PhoneNumber = "1234567890",
UserName = "jdoe@eshop.com", UserName = "demouser@microsoft.com",
ZipCode = "56730", ZipCode = "98052",
State = "Washington", State = "WA",
Street = "Street..", Street = "15703 NE 61st Ct",
SecurityNumber = "256", SecurityNumber = "535",
NormalizedEmail = "JDOE@ESHOP.COM", NormalizedEmail = "DEMOUSER@MICROSOFT.COM",
NormalizedUserName = "JDOE@ESHOP.COM", NormalizedUserName = "DEMOUSER@MICROSOFT.COM",
SecurityStamp = Guid.NewGuid().ToString("D") SecurityStamp = Guid.NewGuid().ToString("D")
}; };
user.PasswordHash = _passwordHasher.HashPassword(user, "eshopContainers.123"); user.PasswordHash = _passwordHasher.HashPassword(user, "Pass@word1");
return user; return user;
} }

View File

@ -13,7 +13,7 @@ namespace eShopOnContainers.Identity
{ {
var host = new WebHostBuilder() var host = new WebHostBuilder()
.UseKestrel() .UseKestrel()
.UseUrls("http://0.0.0.0:5105") .UseUrls("http://0.0.0.0:5000")
.UseContentRoot(Directory.GetCurrentDirectory()) .UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration() .UseIISIntegration()
.UseStartup<Startup>() .UseStartup<Startup>()

View File

@ -53,6 +53,17 @@
Street = order.ShippingStreet 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); var added = await _mediator.SendAsync(newOrderRequest);
if (added) if (added)

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Models namespace Microsoft.eShopOnContainers.Services.Ordering.API.Models
{ {
@ -21,5 +22,12 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Models
public DateTime CardExpiration { get; set; } public DateTime CardExpiration { get; set; }
public string CardSecurityNumber { get; set; } public string CardSecurityNumber { get; set; }
public List<OrderItemViewModel> Items { get; set; }
public NewOrderViewModel()
{
Items = new List<OrderItemViewModel>();
}
} }
} }

View File

@ -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; }
}
}

View File

@ -3,7 +3,7 @@
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:5102/", "applicationUrl": "http://localhost:5002/",
"sslPort": 0 "sslPort": 0
} }
}, },

View File

@ -55,6 +55,11 @@
ZipCode = message.ZipCode ZipCode = message.ZipCode
}); });
foreach (var item in message.OrderItems)
{
order.AddOrderItem(item);
}
_orderRepository.Add(order); _orderRepository.Add(order);
var result = await _orderRepository.UnitOfWork var result = await _orderRepository.UnitOfWork

View File

@ -2,10 +2,15 @@
{ {
using System; using System;
using MediatR; using MediatR;
using Domain;
using System.Collections;
using System.Collections.Generic;
public class NewOrderRequest public class NewOrderRequest
:IAsyncRequest<bool> :IAsyncRequest<bool>
{ {
private readonly List<OrderItem> _orderItems;
public string City { get; set; } public string City { get; set; }
public string Street { get; set; } public string Street { get; set; }
@ -27,5 +32,17 @@
public int CardTypeId { get; set; } public int CardTypeId { get; set; }
public string Buyer { 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>();
}
} }
} }

View File

@ -17,7 +17,7 @@
public OrderStatus Status { get; private set; } 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; } public int? ShippingAddressId { get; private set; }
@ -35,6 +35,7 @@
PaymentId = paymentId; PaymentId = paymentId;
StatusId = OrderStatus.InProcess.Id; StatusId = OrderStatus.InProcess.Id;
OrderDate = DateTime.UtcNow; OrderDate = DateTime.UtcNow;
OrderItems = new List<OrderItem>();
} }
public void SetAddress(Address address) public void SetAddress(Address address)
@ -46,5 +47,12 @@
ShippingAddress = address; 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);
}
} }
} }

View File

@ -6,20 +6,17 @@
public class OrderItem public class OrderItem
:Entity :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()
{
}
} }
} }

View File

@ -40,6 +40,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
{ {
HttpContext.Authentication.SignOutAsync("Cookies"); HttpContext.Authentication.SignOutAsync("Cookies");
HttpContext.Authentication.SignOutAsync("oidc"); HttpContext.Authentication.SignOutAsync("oidc");
return new SignOutResult("oidc", new AuthenticationProperties { RedirectUri = "/" }); return new SignOutResult("oidc", new AuthenticationProperties { RedirectUri = "/" });
} }
} }

View File

@ -42,11 +42,13 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
basket = await _basketSvc.UpdateBasket(basket); basket = await _basketSvc.UpdateBasket(basket);
var order = _basketSvc.MapBasketToOrder(basket); var order = _basketSvc.MapBasketToOrder(basket);
// override if user has changed some shipping address or payment info data. // override if user has changed some shipping address or payment info data.
_orderSvc.OverrideUserInfoIntoOrder(model.Order, order); _orderSvc.OverrideUserInfoIntoOrder(model.Order, order);
if (action == "[ Place Order ]") if (action == "[ Place Order ]")
{ {
await _orderSvc.CreateOrder(user, order); await _orderSvc.CreateOrder(user, order);
//Empty basket for current user. //Empty basket for current user.

View File

@ -8,7 +8,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Models
public class OrderRequest public class OrderRequest
{ {
public OrderRequest() { public OrderRequest() {
Items = new List<OrderRequestItem>();
} }
public string City { get; set; } public string City { get; set; }
@ -32,5 +32,9 @@ namespace Microsoft.eShopOnContainers.WebMVC.Models
public int CardTypeId { get; set; } public int CardTypeId { get; set; }
public string Buyer { get; set; } public string Buyer { get; set; }
public List<OrderRequestItem> Items { get; }
} }
} }

View 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; }
}
}

View File

@ -111,7 +111,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
public OrderRequest MapOrderIntoOrderRequest(Order order) public OrderRequest MapOrderIntoOrderRequest(Order order)
{ {
return new OrderRequest() var od = new OrderRequest()
{ {
CardHolderName = order.PaymentInfo.CardHolderName, CardHolderName = order.PaymentInfo.CardHolderName,
CardNumber = order.PaymentInfo.CardNumber, CardNumber = order.PaymentInfo.CardNumber,
@ -121,8 +121,22 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
Country = order.ShippingAddress.Country, Country = order.ShippingAddress.Country,
State = order.ShippingAddress.State, State = order.ShippingAddress.State,
Street = order.ShippingAddress.Street, 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) async public Task CreateOrder(ApplicationUser user, Order order)

View File

@ -2,7 +2,7 @@
"CatalogUrl": "http://localhost:5101", "CatalogUrl": "http://localhost:5101",
"OrderingUrl": "http://localhost:5102", "OrderingUrl": "http://localhost:5102",
"BasketUrl": "http://localhost:5103", "BasketUrl": "http://localhost:5103",
"IdentityUrl": "http://localhost:5000", "IdentityUrl": "http://localhost:5105",
"CallBackUrl": "http://localhost:5100/", "CallBackUrl": "http://localhost:5100/",
"Logging": { "Logging": {
"IncludeScopes": false, "IncludeScopes": false,