using System;
using System.Collections.Generic;
using System.Text;
using Ubik.Engine.Client;
namespace StoresAndStockPricing.Model{
/// <summary>
/// Price of a stock item at a retail store.
/// </summary>
public class StockItemSellingPrice : Individual
{
private TrackedReference<StockItem> _stockItem;
private TrackedReference<RetailStore> _retailStore;
private TrackedProperty<decimal> _sellingPrice;
private TrackedProperty<DateTime> _effectiveSince;
protected StockItemSellingPrice(Session session)
: base(session)
{
_stockItem = new TrackedReference<StockItem>(this, "StockItem");
_retailStore = new TrackedReference<RetailStore>(this, "RetailStore");
_sellingPrice = new TrackedProperty<decimal>(this, "SellingPrice");
_effectiveSince = new TrackedProperty<DateTime>(this, "EffectiveSince");
}
public StockItemSellingPrice(Session session, StockItem stockItem, RetailStore retailStore, decimal sellingPrice)
: this(session)
{
if (stockItem == null)
throw new ArgumentNullException("stockItem");
if (retailStore == null)
throw new ArgumentNullException("retailStore");
ValidateSellingPrice(sellingPrice);
_effectiveSince.Reset(EngineDateTime.UtcNow);
_stockItem.Reset(stockItem);
_retailStore.Reset(retailStore);
_sellingPrice.Reset(sellingPrice);
}
public static void ValidateSellingPrice(decimal sellingPrice)
{
if (sellingPrice < 0)
throw new ArgumentOutOfRangeException("sellingPrice");
}
public decimal SellingPrice
{
get
{
return _sellingPrice.Value;
}
set
{
ValidateSellingPrice(value);
StockItemHistoricalSellingPrice historicalPrice = new StockItemHistoricalSellingPrice(
Session, StockItem, RetailStore, SellingPrice, EffectiveSince);
historicalPrice.Insert();
_effectiveSince.Value = historicalPrice.EffectiveUntil;
_sellingPrice.Value = value;
}
}
public DateTime EffectiveSince
{
get
{
return _effectiveSince.Value;
}
}
public RetailStore RetailStore
{
get
{
return _retailStore.Value;
}
}
public StockItem StockItem
{
get
{
return _stockItem.Value;
}
}
}
}
|