//returns false, if a move is not possible public bool Move(RiskFactorTypeDetail detail, RiskFactorTypeGroup group) { RiskFactorTypeGroup checkParent = group; detail.RiskFactorTypeGroup = group; detail.RiskFactorTypeGroupID = group.RiskFactorTypeGroupID; //reset the values - we have new version, which is unapproved //it will be finalised during save if (detail.Status == EntityStatus.Approved) detail.Default(Context.UserName); return true; }
//returns false, if a move is not possible public bool Move(RiskFactorTypeGroup item, RiskFactorTypeGroup newParent) { RiskFactorTypeGroup checkParent = newParent; //check for circular reference while ((checkParent != null) && (checkParent != item)) { checkParent = checkParent.RiskFactorTypeGroupParent; } //circular reference check failed - abort movement if (checkParent == item) return false; item.RiskFactorTypeGroupParent = newParent; item.RiskFactorTypeGroupParentID = newParent.RiskFactorTypeGroupID; return true; }
public void TestSaveNewRiskFactorTypeGroup() { using (var context = new ScenarioGeneratorModel(UserName, Connection)) { context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s); string testName = "New Risk Factor Type Group"; RiskFactorTypeGroup rftg = new RiskFactorTypeGroup(); rftg.Default(UserName); context.RiskFactorTypeGroups.Add(rftg); rftg.Name = testName; context.SaveChanges(); Assert.AreEqual(1, context.RiskFactorTypeGroups.Where(x => x.Name == testName).Count()); Assert.AreEqual(DateTime.MinValue, rftg.StartTime); Assert.AreEqual(DateTime.MaxValue, rftg.EndTime); } }
public RiskFactorTypeGroup Add(RiskFactorTypeGroup parent) { RiskFactorTypeGroup item = new RiskFactorTypeGroup(); item.Default(Context.UserName); item.Approve(Context.UserName); if (Context.RiskFactorTypeGroups.Local.Any()) item.RiskFactorTypeGroupID = Context.RiskFactorTypeGroups.Local.Max(x => x.RiskFactorTypeGroupID) + 1; else item.RiskFactorTypeGroupID = 1; Context.RiskFactorTypeGroups.Add(item); if (parent != null) { item.RiskFactorTypeGroupParent = parent; item.RiskFactorTypeGroupParentID = parent.RiskFactorTypeGroupID; } item.Name = "Risk Factor Type Group Name"; return item; }
internal static void AddTypeGroups(ScenarioGeneratorModel context) { DateTime now = context.AsOfDate; RiskFactorTypeGroup ftg = new RiskFactorTypeGroup(); ftg.Default(context.UserName); ftg.Name = "Credit"; context.RiskFactorTypeGroups.Add(ftg); RiskFactorTypeGroup ftgc = new RiskFactorTypeGroup(); ftgc.Default(context.UserName); ftgc.Name = "Spread"; ftg.RiskFactorTypeGroupChildren.Add(ftgc); ftg = new RiskFactorTypeGroup(); ftg.Default(context.UserName); ftg.Name = "FX"; context.RiskFactorTypeGroups.Add(ftg); ftgc = new RiskFactorTypeGroup(); ftgc.Default(context.UserName); ftgc.Name = "Rate"; ftg.RiskFactorTypeGroupChildren.Add(ftgc); ftgc = new RiskFactorTypeGroup(); ftgc.Default(context.UserName); ftgc.Name = "Volatility"; ftg.RiskFactorTypeGroupChildren.Add(ftgc); ftg = new RiskFactorTypeGroup(); ftg.Default(context.UserName); ftg.Name = "IL"; context.RiskFactorTypeGroups.Add(ftg); ftgc = new RiskFactorTypeGroup(); ftgc.Default(context.UserName); ftgc.Name = "Rate"; ftg.RiskFactorTypeGroupChildren.Add(ftgc); ftgc = new RiskFactorTypeGroup(); ftgc.Default(context.UserName); ftgc.Name = "Volatility"; ftg.RiskFactorTypeGroupChildren.Add(ftgc); ftg = new RiskFactorTypeGroup(); ftg.Default(context.UserName); ftg.Name = "IR"; context.RiskFactorTypeGroups.Add(ftg); ftgc = new RiskFactorTypeGroup(); ftgc.Default(context.UserName); ftgc.Name = "Spread"; ftg.RiskFactorTypeGroupChildren.Add(ftgc); ftgc = new RiskFactorTypeGroup(); ftgc.Default(context.UserName); ftgc.Name = "Rate"; ftg.RiskFactorTypeGroupChildren.Add(ftgc); ftgc = new RiskFactorTypeGroup(); ftgc.Default(context.UserName); ftgc.Name = "Volatility"; ftg.RiskFactorTypeGroupChildren.Add(ftgc); context.SaveChanges(); }