public RiskFactorTypeDimension AddRiskFactorDimenstion(RiskFactorType type, RiskFactorDimension dimension) { var persisted = Context.RiskFactorTypeDimensions.Where(x => x.RiskFactorDimensionID == dimension.RiskFactorDimensionID && x.RiskFactorTypeID == type.RiskFactorTypeID).FirstOrDefault(); if (persisted != null && Context.Entry(persisted).State == EntityState.Modified) { // remove any changes Context.Entry(persisted).State = EntityState.Unchanged; return persisted; } var detail = new RiskFactorTypeDimension(); detail.Default(Context.UserName); detail.RiskFactorDimension = dimension; detail.RiskFactorType = type; Context.RiskFactorTypeDimensions.Add(detail); return detail; }
public RiskFactorTypeDetail Add() { // there is no hierarchy so parent can be safely ignored RiskFactorTypeDetail detail = new RiskFactorTypeDetail(); detail.Default(Context.UserName); RiskFactorType main = new RiskFactorType(); main.Default(Context.UserName); if (Context.RiskFactorTypes.Local.Count() > 0) main.RiskFactorTypeID = Context.RiskFactorTypes.Local.Max(x => x.RiskFactorTypeID) + 1; else main.RiskFactorTypeID = 1; detail.RiskFactorType = main; detail.RiskFactorTypeID = main.RiskFactorTypeID; detail.Name = "Risk Factor Type Name"; Context.RiskFactorTypes.Add(main); Context.RiskFactorTypeDetails.Add(detail); return detail; }
public RiskFactorDetails(RiskFactorType type) { Type = type; }
internal static void AddTypes(ScenarioGeneratorModel context) { DateTime now = context.AsOfDate; RiskFactorType rft; RiskFactorTypeDetail rftd; rft = new RiskFactorType() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-80), ApprovedBy = "B", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "Credit Asset Swap Spread", StartTime = now.AddDays(-20), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-25), CreatedBy = "A", ApprovedAt = now.AddDays(-20), ApprovedBy = "B", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Spread").Where(x =>x.RiskFactorTypeGroupParent.Name == "Credit").First(); rft = new RiskFactorType() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-80), ApprovedBy = "B", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "Credit CDS Composites Spread", StartTime = now.AddDays(-20), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-25), CreatedBy = "A", ApprovedAt = now.AddDays(-20), ApprovedBy = "B", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Spread").Where(x => x.RiskFactorTypeGroupParent.Name == "Credit").First(); rft = new RiskFactorType() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-80), ApprovedBy = "B", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "Credit CDS Index Spread", StartTime = now.AddDays(-20), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-25), CreatedBy = "A", ApprovedAt = now.AddDays(-20), ApprovedBy = "B", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Spread").Where(x => x.RiskFactorTypeGroupParent.Name == "Credit").First(); rft = new RiskFactorType() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-80), ApprovedBy = "B", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "FX Rate", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-40), CreatedBy = "A", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Rate").Where(x => x.RiskFactorTypeGroupParent.Name == "FX").First(); rft = new RiskFactorType() { StartTime = now.AddDays(-50), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-50), ApprovedBy = "B", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "FX Volatility", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-40), CreatedBy = "A", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Volatility").Where(x => x.RiskFactorTypeGroupParent.Name == "FX").First(); rft = new RiskFactorType() { StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-40), CreatedBy = "A", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "IL Rate", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-150), CreatedBy = "A", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Rate").Where(x => x.RiskFactorTypeGroupParent.Name == "IL").First(); rft = new RiskFactorType() { StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-40), CreatedBy = "A", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "IL Volatility", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-150), CreatedBy = "A", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Volatility").Where(x => x.RiskFactorTypeGroupParent.Name == "IL").First(); rft = new RiskFactorType() { StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-40), CreatedBy = "A", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "IR Volatility", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-150), CreatedBy = "A", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Volatility").Where(x => x.RiskFactorTypeGroupParent.Name == "IR").First(); rft = new RiskFactorType() { StartTime = now.AddDays(-80), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "IR LIBOR Spread (v1)", StartTime = now.AddDays(-100), EndTime = now.AddDays(-50), CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = false }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Spread").Where(x => x.RiskFactorTypeGroupParent.Name == "IR").First(); rftd = new RiskFactorTypeDetail() { Name = "IR LIBOR Spread (v2)", StartTime = now.AddDays(-50), EndTime = now.AddDays(-10), CreatedAt = now.AddDays(-90), CreatedBy = "A", ApprovedAt = now.AddDays(-50), ApprovedBy = "B", Latest = false }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Spread").Where(x => x.RiskFactorTypeGroupParent.Name == "IR").First(); rftd = new RiskFactorTypeDetail() { Name = "IR LIBOR Spread (v3)", StartTime = now.AddDays(-10), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-40), CreatedBy = "A", ApprovedAt = now.AddDays(-10), ApprovedBy = "B", Latest = false }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Rate").Where(x => x.RiskFactorTypeGroupParent.Name == "IR").First(); rftd = new RiskFactorTypeDetail() { Name = "IR LIBOR Spread", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-30), CreatedBy = "A", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Spread").Where(x => x.RiskFactorTypeGroupParent.Name == "IR").First(); context.SaveChanges(); }