Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalis authored May 29, 2018
1 parent 5b268b2 commit 8169d2f
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 32 deletions.
28 changes: 0 additions & 28 deletions src/ApplicationCore/Entities/Basket.cs

This file was deleted.

29 changes: 29 additions & 0 deletions src/ApplicationCore/Entities/BasketAggregate/Basket.cs
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;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Microsoft.eShopWeb.ApplicationCore.Entities
namespace Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate
{
public class BasketItem : BaseEntity
{
Expand Down
3 changes: 2 additions & 1 deletion src/ApplicationCore/Exceptions/GuardExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using ApplicationCore.Exceptions;
using Microsoft.eShopWeb.ApplicationCore.Entities;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;

namespace Ardalis.GuardClauses
{
public static class FooGuard
public static class BasketGuards
{
public static void NullBasket(this IGuardClause guardClause, int basketId, Basket basket)
{
Expand Down
1 change: 1 addition & 0 deletions src/ApplicationCore/Services/BasketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.eShopWeb.ApplicationCore.Entities;
using System.Linq;
using Ardalis.GuardClauses;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;

namespace ApplicationCore.Services
{
Expand Down
1 change: 1 addition & 0 deletions src/ApplicationCore/Services/OrderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.eShopWeb.ApplicationCore.Entities;
using System.Collections.Generic;
using Ardalis.GuardClauses;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;

namespace ApplicationCore.Services
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.eShopWeb.ApplicationCore.Entities;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;

namespace ApplicationCore.Specifications
{
Expand Down
1 change: 1 addition & 0 deletions src/Infrastructure/Data/CatalogContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.eShopWeb.ApplicationCore.Entities;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;

namespace Infrastructure.Data
{
Expand Down
4 changes: 2 additions & 2 deletions src/Web/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5106/",
"sslPort": 44316
"sslPort": 0
}
},
"profiles": {
Expand All @@ -16,7 +16,7 @@
}
},
"eShopWeb": {
"commandName": "IISExpress",
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
1 change: 1 addition & 0 deletions src/Web/Services/BasketViewModelService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ApplicationCore.Interfaces;
using ApplicationCore.Specifications;
using Microsoft.eShopWeb.ApplicationCore.Entities;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using Microsoft.eShopWeb.Interfaces;
using Microsoft.eShopWeb.ViewModels;
using System.Collections.Generic;
Expand Down
1 change: 1 addition & 0 deletions src/WebRazorPages/Services/BasketViewModelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using ApplicationCore.Specifications;
using Microsoft.eShopWeb.RazorPages.Interfaces;
using Microsoft.eShopWeb.RazorPages.ViewModels;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;

namespace Microsoft.eShopWeb.RazorPages.Services
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.eShopWeb.ApplicationCore.Entities;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using System.Linq;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ApplicationCore.Interfaces;
using ApplicationCore.Services;
using Microsoft.eShopWeb.ApplicationCore.Entities;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using Moq;
using System;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ApplicationCore.Specifications;
using Microsoft.eShopWeb.ApplicationCore.Entities;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using System.Collections.Generic;
using System.Linq;
using Xunit;
Expand Down

0 comments on commit 8169d2f

Please sign in to comment.