Initial Upgrade to .NET Core 2.0 (#50)
* Ardalis/upgrade1 (#44) * Upgrading to netcore 2.0 Updating repository to support async options and refactoring to use it. * Starting work on tracking customer orders feature. * Cleaning up some bugs Working on basket view component implementation * Fixing up styles, especially for basket in header. * Adding Order Features (#47) * Working on order model binding from checkout page - WIP * Small layout tweaks (#43) * Updating quantities implemented. * Fixed basket widget count * Order History (#49) * working on creating and viewing orders. * Working on wiring up listing of orders * List orders page works as expected. Needed to support ThenInclude scenarios. Currently using strings.
This commit is contained in:
39
src/ApplicationCore/Entities/OrderAggregate/Address.cs
Normal file
39
src/ApplicationCore/Entities/OrderAggregate/Address.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ApplicationCore.Entities.OrderAggregate
|
||||
{
|
||||
public class Address // ValueObject
|
||||
{
|
||||
public String Street { get; private set; }
|
||||
|
||||
public String City { get; private set; }
|
||||
|
||||
public String State { get; private set; }
|
||||
|
||||
public String Country { get; private set; }
|
||||
|
||||
public String ZipCode { get; private set; }
|
||||
|
||||
private Address() { }
|
||||
|
||||
public Address(string street, string city, string state, string country, string zipcode)
|
||||
{
|
||||
Street = street;
|
||||
City = city;
|
||||
State = state;
|
||||
Country = country;
|
||||
ZipCode = zipcode;
|
||||
}
|
||||
|
||||
//protected override IEnumerable<object> GetAtomicValues()
|
||||
//{
|
||||
// yield return Street;
|
||||
// yield return City;
|
||||
// yield return State;
|
||||
// yield return Country;
|
||||
// yield return ZipCode;
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace ApplicationCore.Entities.OrderAggregate
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the item that was ordered. If catalog item details change, details of
|
||||
/// the item that was part of a completed order should not change.
|
||||
/// </summary>
|
||||
public class CatalogItemOrdered // ValueObject
|
||||
{
|
||||
public CatalogItemOrdered(int catalogItemId, string productName, string pictureUri)
|
||||
{
|
||||
CatalogItemId = catalogItemId;
|
||||
ProductName = productName;
|
||||
PictureUri = pictureUri;
|
||||
}
|
||||
private CatalogItemOrdered()
|
||||
{
|
||||
// required by EF
|
||||
}
|
||||
public int CatalogItemId { get; private set; }
|
||||
public string ProductName { get; private set; }
|
||||
public string PictureUri { get; private set; }
|
||||
}
|
||||
}
|
||||
48
src/ApplicationCore/Entities/OrderAggregate/Order.cs
Normal file
48
src/ApplicationCore/Entities/OrderAggregate/Order.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using ApplicationCore.Interfaces;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ApplicationCore.Entities.OrderAggregate
|
||||
{
|
||||
public class Order : BaseEntity, IAggregateRoot
|
||||
{
|
||||
private Order()
|
||||
{
|
||||
}
|
||||
|
||||
public Order(string buyerId, Address shipToAddress, List<OrderItem> items)
|
||||
{
|
||||
ShipToAddress = shipToAddress;
|
||||
_orderItems = items;
|
||||
BuyerId = buyerId;
|
||||
}
|
||||
public string BuyerId { get; private set; }
|
||||
|
||||
public DateTimeOffset OrderDate { get; private set; } = DateTimeOffset.Now;
|
||||
public Address ShipToAddress { get; private set; }
|
||||
|
||||
// DDD Patterns comment
|
||||
// Using a private collection field, better for DDD Aggregate's encapsulation
|
||||
// so OrderItems cannot be added from "outside the AggregateRoot" directly to the collection,
|
||||
// but only through the method Order.AddOrderItem() which includes behavior.
|
||||
private readonly List<OrderItem> _orderItems = new List<OrderItem>();
|
||||
|
||||
public IReadOnlyCollection<OrderItem> OrderItems => _orderItems;
|
||||
// Using List<>.AsReadOnly()
|
||||
// This will create a read only wrapper around the private list so is protected against "external updates".
|
||||
// It's much cheaper than .ToList() because it will not have to copy all items in a new collection. (Just one heap alloc for the wrapper instance)
|
||||
//https://msdn.microsoft.com/en-us/library/e78dcd75(v=vs.110).aspx
|
||||
|
||||
public decimal Total()
|
||||
{
|
||||
var total = 0m;
|
||||
foreach (var item in _orderItems)
|
||||
{
|
||||
total += item.UnitPrice * item.Units;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
22
src/ApplicationCore/Entities/OrderAggregate/OrderItem.cs
Normal file
22
src/ApplicationCore/Entities/OrderAggregate/OrderItem.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
|
||||
namespace ApplicationCore.Entities.OrderAggregate
|
||||
{
|
||||
|
||||
public class OrderItem : BaseEntity
|
||||
{
|
||||
public CatalogItemOrdered ItemOrdered { get; private set; }
|
||||
public decimal UnitPrice { get; private set; }
|
||||
public int Units { get; private set; }
|
||||
|
||||
protected OrderItem()
|
||||
{
|
||||
}
|
||||
public OrderItem(CatalogItemOrdered itemOrdered, decimal unitPrice, int units)
|
||||
{
|
||||
ItemOrdered = itemOrdered;
|
||||
UnitPrice = unitPrice;
|
||||
Units = units;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user