-
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
Simon Chester
committed
Nov 26, 2021
1 parent
aba4d24
commit e401f34
Showing
3 changed files
with
56 additions
and
4 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
28 changes: 28 additions & 0 deletions
28
ChestersCheckout/ChestersCheckout.Core/Services/Discounting/ThreeForTwoDiscounterService.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,28 @@ | ||
using ChestersCheckout.Core.Models; | ||
using ChestersCheckout.Core.Services.Abstractions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ChestersCheckout.Core.Services.Discounting | ||
{ | ||
public class ThreeForTwoDiscounterService : IDiscounterService | ||
{ | ||
private readonly string _productName; | ||
|
||
public ThreeForTwoDiscounterService(string productName) | ||
{ | ||
_productName = productName; | ||
} | ||
|
||
public int CalculateDiscount(Basket basket) | ||
{ | ||
if (!basket.Items.TryGetValue(_productName, out var item)) | ||
return 0; | ||
|
||
return item.UnitPrice * (item.Quantity / 3); | ||
} | ||
} | ||
} |