using System;
using System.Collections.Generic;
using System.Text;
using Ubik.Engine.Client;
namespace StoresAndStockPricing.Model{
/// <summary>
/// Scheduled change to a stock item's selling price
/// </summary>
public class StockItemSellingPriceMaintenanceEvent : DataMaintenanceEvent
{
TrackedReference<StockItem> _stockItem;
TrackedReference<RetailStoreGroup> _targetRetailStoreGroup;
TrackedProperty<decimal> _sellingPrice;
protected StockItemSellingPriceMaintenanceEvent(Session session)
: base(session)
{
CreateProperties();
}
public StockItemSellingPriceMaintenanceEvent(
Session session,
DateTime plannedDateTime,
StockItem stockItem,
RetailStoreGroup targetRetailStoreGroup,
decimal sellingPrice
)
: base(session, plannedDateTime)
{
if (stockItem == null)
throw new ArgumentNullException("stockItem");
if (targetRetailStoreGroup == null)
throw new ArgumentNullException("targetRetailStoreGroup");
StockItemSellingPrice.ValidateSellingPrice(sellingPrice);
CreateProperties();
_stockItem.Reset(stockItem);
_targetRetailStoreGroup.Reset(targetRetailStoreGroup);
_sellingPrice.Reset(sellingPrice);
}
private void CreateProperties()
{
_stockItem = new TrackedReference<StockItem>(this, "StockItem");
_targetRetailStoreGroup = new TrackedReference<RetailStoreGroup>(this, "TargetRetailStoreGroup");
_sellingPrice = new TrackedProperty<decimal>(this, "SellingPrice");
}
public StockItem StockItem
{
get
{
return _stockItem.Value;
}
}
public RetailStoreGroup TargetRetailStoreGroup
{
get
{
return _targetRetailStoreGroup.Value;
}
}
public decimal SellingPrice
{
get
{
return _sellingPrice.Value;
}
}
public override string Description
{
get
{
return string.Format(StockItemSellingPriceMaintenanceEventResources.Description,
StockItem.Name, TargetRetailStoreGroup.Name, SellingPrice.ToString());
}
}
protected override void ApplyImpl()
{
foreach (RetailStore store in TargetRetailStoreGroup.RetailStores)
{
StockItem.ChangeSellingPrice(store, SellingPrice);
}
}
}
}
|