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.
- Loading branch information
Showing
14 changed files
with
43 additions
and
32 deletions.
There are no files selected for viewing
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,29 @@ | ||
using ApplicationCore.Interfaces; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate | ||
{ | ||
public class Basket : BaseEntity, IAggregateRoot | ||
{ | ||
public string BuyerId { get; set; } | ||
private readonly List<BasketItem> _items = new List<BasketItem>(); | ||
public IReadOnlyCollection<BasketItem> Items => _items.AsReadOnly(); | ||
|
||
public void AddItem(int catalogItemId, decimal unitPrice, int quantity = 1) | ||
{ | ||
if (!Items.Any(i => i.CatalogItemId == catalogItemId)) | ||
{ | ||
_items.Add(new BasketItem() | ||
{ | ||
CatalogItemId = catalogItemId, | ||
Quantity = quantity, | ||
UnitPrice = unitPrice | ||
}); | ||
return; | ||
} | ||
var existingItem = Items.FirstOrDefault(i => i.CatalogItemId == catalogItemId); | ||
existingItem.Quantity += quantity; | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/ApplicationCore/Entities/BasketItem.cs → ...re/Entities/BasketAggregate/BasketItem.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
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
1 change: 1 addition & 0 deletions
1
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
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
1 change: 1 addition & 0 deletions
1
tests/UnitTests/ApplicationCore/Entities/BasketTests/AddItem.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
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
1 change: 1 addition & 0 deletions
1
tests/UnitTests/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