Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created February 22, 2024 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomartin/9432025b43e02193b2ade0a73e539f63 to your computer and use it in GitHub Desktop.
Save dcomartin/9432025b43e02193b2ade0a73e539f63 to your computer and use it in GitHub Desktop.
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