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; }
internal static void AddTypeDimensions(ScenarioGeneratorModel context) { RiskFactorTypeDetail rft; RiskFactorDimensionDetail rfd; RiskFactorTypeDimension rftd; rft = context.RiskFactorTypeDetails.Where(d => (d.Name == "FX Rate" && d.Latest==true)).First(); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Currency" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID } ; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Instrument Tenor" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rft = context.RiskFactorTypeDetails.Where(d => (d.Name == "FX Volatility" && d.Latest == true)).First(); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Currency" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Instrument Tenor" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Country of Origin" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rft = context.RiskFactorTypeDetails.Where(d => (d.Name == "Credit Asset Swap Spread" && d.Latest == true)).First(); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Instrument Sector" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Obligor Rating" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rft = context.RiskFactorTypeDetails.Where(d => (d.Name == "IR Volatility" && d.Latest == true)).First(); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Currency" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Instrument Tenor" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Underlying Tenor" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); context.SaveChanges(); }
public void RemoveRiskFactorDimItemDetail(RiskFactorTypeDimension item) { if (Context.Entry(item).State == EntityState.Added) { // safely remove item as it has not yet been persisted Context.RiskFactorTypeDimensions.Remove(item); } else { item.Expire(Context.UserName); item.Latest = false; } }