using System;
using System.Collections.Generic;
using System.Text;
using Ubik.Engine.Client;
namespace StoresAndStockPricing.Model{
/// <summary>
/// Add system defaults to a model.
/// </summary>
public static class Setup
{
/// <summary>
/// Make sure the model on <paramref name="session"/> contains all required system defaults.
/// </summary>
/// <param name="session">Must not be null.</param>
public static void InitialiseModel(Session session)
{
if (session == null)
throw new ArgumentNullException("session");
using (Transaction txn = session.BeginTransaction())
{
// Create the system RetailStoreGroupFunction
if (session.Select<RetailStoreGroupFunction>("IsSystemFunction = true").Count == 0)
{
RetailStoreGroupFunction systemFunction = new RetailStoreGroupFunction(session, SetupResources.SystemRetailStoreGroupFunctionName);
systemFunction.Insert();
systemFunction.IsSystemFunction = true;
RetailStoreGroup allStores = new RetailStoreGroup(session, SetupResources.AllStoresGroupName, systemFunction);
allStores.Insert();
RetailStore localStore = new RetailStore(session, SetupResources.LocalStoreName, EngineDateTime.UtcNow);
localStore.Insert();
}
txn.Commit();
}
}
}
}
|