-
-
Save dcomartin/9432025b43e02193b2ade0a73e539f63 to your computer and use it in GitHub Desktop.
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
public class WarehouseProduct | |
{ | |
public string Sku { get; private set; } | |
public string Name { get; private set; } | |
public string Description { get; private set; } | |
public decimal Price { get; private set; } | |
public int QuantityOnHand { get; private set; } | |
public void SetName(string name) | |
{ | |
if (string.IsNullOrWhiteSpace(name)) | |
{ | |
throw new ArgumentException("Name cannot be blank."); | |
} | |
Name = name; | |
} | |
public void SetDescription(string description) | |
{ | |
Description = description; | |
} | |
public void SetPrice(decimal price) | |
{ | |
if (price < 0) | |
{ | |
throw new ArgumentException("Price must be greater than 0."); | |
} | |
Price = price; | |
} | |
public void ShipProduct(int quantity) | |
{ | |
if (quantity > QuantityOnHand) | |
{ | |
throw new InvalidDomainException("Ah... we don't have enough product to ship!"); | |
} | |
QuantityOnHand -= quantity; | |
} | |
public void ReceiveProduct(int quantity) | |
{ | |
QuantityOnHand += quantity; | |
} | |
public void AdjustInventory(int quantity) | |
{ | |
if (QuantityOnHand + quantity < 0) | |
{ | |
throw new InvalidDomainException("Cannot adjust to a negative quantity on hand."); | |
} | |
QuantityOnHand += quantity; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment