forked from dotnet-architecture/eShopOnWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Upgrade to .NET Core 2.0 (dotnet-architecture#50)
* Ardalis/upgrade1 (dotnet-architecture#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 (dotnet-architecture#47) * Working on order model binding from checkout page - WIP * Small layout tweaks (dotnet-architecture#43) * Updating quantities implemented. * Fixed basket widget count * Order History (dotnet-architecture#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.
- Loading branch information
Showing
70 changed files
with
1,752 additions
and
510 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using ApplicationCore.Interfaces; | ||
using Microsoft.eShopWeb.ApplicationCore.Entities; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace ApplicationCore.Entities.BuyerAggregate | ||
{ | ||
public class Buyer : BaseEntity, IAggregateRoot | ||
{ | ||
public string IdentityGuid { get; private set; } | ||
|
||
private List<PaymentMethod> _paymentMethods = new List<PaymentMethod>(); | ||
|
||
public IEnumerable<PaymentMethod> PaymentMethods => _paymentMethods.AsReadOnly(); | ||
|
||
protected Buyer() | ||
{ | ||
} | ||
|
||
public Buyer(string identity) : this() | ||
{ | ||
IdentityGuid = !string.IsNullOrWhiteSpace(identity) ? identity : throw new ArgumentNullException(nameof(identity)); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/ApplicationCore/Entities/BuyerAggregate/PaymentMethod.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Microsoft.eShopWeb.ApplicationCore.Entities; | ||
|
||
namespace ApplicationCore.Entities.BuyerAggregate | ||
{ | ||
public class PaymentMethod : BaseEntity | ||
{ | ||
public string Alias { get; set; } | ||
public string CardId { get; set; } // actual card data must be stored in a PCI compliant system, like Stripe | ||
public string Last4 { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
//} | ||
|
||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/ApplicationCore/Entities/OrderAggregate/CatalogItemOrdered.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace ApplicationCore.Interfaces | ||
{ | ||
public interface IAggregateRoot | ||
{ } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.eShopWeb.ApplicationCore.Entities; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace ApplicationCore.Interfaces | ||
{ | ||
public interface IAsyncRepository<T> where T : BaseEntity | ||
{ | ||
Task<T> GetByIdAsync(int id); | ||
Task<List<T>> ListAllAsync(); | ||
Task<List<T>> ListAsync(ISpecification<T> spec); | ||
Task<T> AddAsync(T entity); | ||
Task UpdateAsync(T entity); | ||
Task DeleteAsync(T entity); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using ApplicationCore.Entities.OrderAggregate; | ||
using System.Threading.Tasks; | ||
|
||
namespace ApplicationCore.Interfaces | ||
{ | ||
|
||
public interface IOrderRepository : IRepository<Order>, IAsyncRepository<Order> | ||
{ | ||
Order GetByIdWithItems(int id); | ||
Task<Order> GetByIdWithItemsAsync(int id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using ApplicationCore.Entities.OrderAggregate; | ||
using System.Threading.Tasks; | ||
|
||
namespace ApplicationCore.Interfaces | ||
{ | ||
public interface IOrderService | ||
{ | ||
Task CreateOrderAsync(int basketId, Address shippingAddress); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/ApplicationCore/Specifications/CustomerOrdersWithItemsSpecification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using ApplicationCore.Interfaces; | ||
using System; | ||
using System.Linq.Expressions; | ||
using System.Collections.Generic; | ||
using ApplicationCore.Entities.OrderAggregate; | ||
|
||
namespace ApplicationCore.Specifications | ||
{ | ||
public class CustomerOrdersWithItemsSpecification : ISpecification<Order> | ||
{ | ||
private readonly string _buyerId; | ||
|
||
public CustomerOrdersWithItemsSpecification(string buyerId) | ||
{ | ||
_buyerId = buyerId; | ||
AddInclude(o => o.OrderItems); | ||
AddInclude("OrderItems.ItemOrdered"); | ||
} | ||
|
||
public Expression<Func<Order, bool>> Criteria => o => o.BuyerId == _buyerId; | ||
|
||
public List<Expression<Func<Order, object>>> Includes { get; } = new List<Expression<Func<Order, object>>>(); | ||
public List<string> IncludeStrings { get; } = new List<string>(); | ||
|
||
public void AddInclude(Expression<Func<Order, object>> includeExpression) | ||
{ | ||
Includes.Add(includeExpression); | ||
} | ||
|
||
public void AddInclude(string includeString) | ||
{ | ||
IncludeStrings.Add(includeString); | ||
} | ||
} | ||
} |
Oops, something went wrong.