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.
Using Base Specification Class (dotnet-architecture#56)
* 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. * Remove non-icon basket link from header Add comments to EF query logic * Refactoring to use base specification type * minor cleanup
- Loading branch information
Showing
7 changed files
with
47 additions
and
76 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,27 @@ | ||
using ApplicationCore.Interfaces; | ||
using System; | ||
using System.Linq.Expressions; | ||
using System.Collections.Generic; | ||
|
||
namespace ApplicationCore.Specifications | ||
{ | ||
public abstract class BaseSpecification<T> : ISpecification<T> | ||
{ | ||
public BaseSpecification(Expression<Func<T, bool>> criteria) | ||
{ | ||
Criteria = criteria; | ||
} | ||
public Expression<Func<T, bool>> Criteria { get; } | ||
public List<Expression<Func<T, object>>> Includes { get; } = new List<Expression<Func<T, object>>>(); | ||
public List<string> IncludeStrings { get; } = new List<string>(); | ||
|
||
protected virtual void AddInclude(Expression<Func<T, object>> includeExpression) | ||
{ | ||
Includes.Add(includeExpression); | ||
} | ||
protected virtual void AddInclude(string includeString) | ||
{ | ||
IncludeStrings.Add(includeString); | ||
} | ||
} | ||
} |
29 changes: 4 additions & 25 deletions
29
src/ApplicationCore/Specifications/BasketWithItemsSpecification.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 |
---|---|---|
@@ -1,39 +1,18 @@ | ||
using ApplicationCore.Interfaces; | ||
using Microsoft.eShopWeb.ApplicationCore.Entities; | ||
using System; | ||
using System.Linq.Expressions; | ||
using System.Collections.Generic; | ||
using ApplicationCore.Entities.OrderAggregate; | ||
using Microsoft.eShopWeb.ApplicationCore.Entities; | ||
|
||
namespace ApplicationCore.Specifications | ||
{ | ||
public class BasketWithItemsSpecification : ISpecification<Basket> | ||
public class BasketWithItemsSpecification : BaseSpecification<Basket> | ||
{ | ||
public BasketWithItemsSpecification(int basketId) | ||
:base(b => b.Id == basketId) | ||
{ | ||
BasketId = basketId; | ||
AddInclude(b => b.Items); | ||
} | ||
public BasketWithItemsSpecification(string buyerId) | ||
:base(b => b.BuyerId == buyerId) | ||
{ | ||
BuyerId = buyerId; | ||
AddInclude(b => b.Items); | ||
} | ||
|
||
public int? BasketId { get; } | ||
public string BuyerId { get; } | ||
|
||
public Expression<Func<Basket, bool>> Criteria => b => | ||
(BasketId.HasValue && b.Id == BasketId.Value) | ||
|| (BuyerId != null && b.BuyerId == BuyerId); | ||
|
||
public List<Expression<Func<Basket, object>>> Includes { get; } = new List<Expression<Func<Basket, object>>>(); | ||
|
||
public List<string> IncludeStrings { get; } = new List<string>(); | ||
|
||
public void AddInclude(Expression<Func<Basket, object>> includeExpression) | ||
{ | ||
Includes.Add(includeExpression); | ||
} | ||
} | ||
} |
28 changes: 4 additions & 24 deletions
28
src/ApplicationCore/Specifications/CatalogFilterSpecification.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 |
---|---|---|
@@ -1,34 +1,14 @@ | ||
using ApplicationCore.Interfaces; | ||
using Microsoft.eShopWeb.ApplicationCore.Entities; | ||
using System; | ||
using System.Linq.Expressions; | ||
using System.Collections.Generic; | ||
using Microsoft.eShopWeb.ApplicationCore.Entities; | ||
|
||
namespace ApplicationCore.Specifications | ||
{ | ||
|
||
public class CatalogFilterSpecification : ISpecification<CatalogItem> | ||
public class CatalogFilterSpecification : BaseSpecification<CatalogItem> | ||
{ | ||
public CatalogFilterSpecification(int? brandId, int? typeId) | ||
: base(i => (!brandId.HasValue || i.CatalogBrandId == brandId) && | ||
(!typeId.HasValue || i.CatalogTypeId == typeId)) | ||
{ | ||
BrandId = brandId; | ||
TypeId = typeId; | ||
} | ||
|
||
public int? BrandId { get; } | ||
public int? TypeId { get; } | ||
|
||
public Expression<Func<CatalogItem, bool>> Criteria => | ||
i => (!BrandId.HasValue || i.CatalogBrandId == BrandId) && | ||
(!TypeId.HasValue || i.CatalogTypeId == TypeId); | ||
|
||
public List<Expression<Func<CatalogItem, object>>> Includes { get; } = new List<Expression<Func<CatalogItem, object>>>(); | ||
|
||
public List<string> IncludeStrings { get; } = new List<string>(); | ||
|
||
public void AddInclude(Expression<Func<CatalogItem, object>> includeExpression) | ||
{ | ||
Includes.Add(includeExpression); | ||
} | ||
} | ||
} |
27 changes: 3 additions & 24 deletions
27
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 |
---|---|---|
@@ -1,35 +1,14 @@ | ||
using ApplicationCore.Interfaces; | ||
using System; | ||
using System.Linq.Expressions; | ||
using System.Collections.Generic; | ||
using ApplicationCore.Entities.OrderAggregate; | ||
using ApplicationCore.Entities.OrderAggregate; | ||
|
||
namespace ApplicationCore.Specifications | ||
{ | ||
public class CustomerOrdersWithItemsSpecification : ISpecification<Order> | ||
public class CustomerOrdersWithItemsSpecification : BaseSpecification<Order> | ||
{ | ||
private readonly string _buyerId; | ||
|
||
public CustomerOrdersWithItemsSpecification(string buyerId) | ||
: base(o => o.BuyerId == 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); | ||
} | ||
} | ||
} |
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