示例#1
0
        public CurveConstituent AddRiskFactorDimItemDetail(RiskFactorDimItemDetail item, CurveDetail curve, RiskFactorDimension dimension)
        {
            var existingDim = curve.Curve.CurveDimensions.FirstOrDefault(x => x.RiskFactorDimensionID == dimension.RiskFactorDimensionID);
            CurveConstituent persisted = null;

            if (existingDim != null)
            {
                persisted = existingDim.CurveConstituents.Where(x => x.RiskFactorDimItemID == item.RiskFactorDimItemID
                                                              && x.CurveDimension.RiskFactorDimensionID == dimension.RiskFactorDimensionID
                                                              && x.CurveDimension.CurveID == curve.CurveID).FirstOrDefault();
            }

            if (persisted != null && Context.Entry(persisted).State == EntityState.Modified)
            {
                // remove any changes
                Context.Entry(persisted).State = EntityState.Unchanged;
                return persisted;
            }

            var detail = new CurveConstituent();
            detail.Default(Context.UserName);
            detail.CurveConstituentID = Context.CurveConstituents.Count() > 0 ? Context.CurveConstituents.Max(x => x.CurveConstituentID) + 1 : 1;
            var dim = curve.Curve.CurveDimensions.FirstOrDefault(x => x.RiskFactorDimensionID == dimension.RiskFactorDimensionID);
            if (dim == null)
            {
                var newDim = new CurveDimension();
                newDim.Approve(Context.UserName);
                newDim.CurveDimensionID = Context.CurveDimensions.Count() > 0 ? Context.CurveDimensions.Max(x => x.CurveDimensionID) + 1 : 1;
                newDim.Default(Context.UserName);
                newDim.RiskFactorDimensionID = dimension.RiskFactorDimensionID;
                detail.CurveDimension = newDim;
                newDim.Curve = curve.Curve;
                curve.Curve.CurveDimensions.Add(newDim);
                Context.CurveDimensions.Add(newDim);
            }
            else
            {
                detail.CurveDimension = dim;
            }

            detail.RiskFactorDimItem = item.RiskFactorDimItem;
            Context.CurveConstituents.Add(detail);

            return detail;
        }
示例#2
0
        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 RiskFactorDimensionDetail AddRiskFactorDimension()
        {
            var record = new RiskFactorDimension();
            var detail = new RiskFactorDimensionDetail();
            record.RiskFactorDimensionDetails.Add(detail);
            detail.RiskFactorDimension = record;
            detail.Default(Context.UserName);
            record.Default(Context.UserName);

            detail.Name = "Risk Factor Dimension Name";
            if (Context.RiskFactorDimensionDetails.Local.Count() > 0)
            {
                detail.RiskFactorDimensionDetailID = Context.RiskFactorDimensionDetails.Local.Max(x => x.RiskFactorDimensionDetailID) + 1;
            }
            else
            {
                detail.RiskFactorDimensionDetailID = 1;
            }
            Context.RiskFactorDimensionDetails.Add(detail);
            return detail;
        }
示例#4
0
        public void RemoveRiskFactorDimItemDetail(RiskFactorDimItemDetail item, CurveDetail curve, RiskFactorDimension dimension)
        {
            var dim = curve.Curve.CurveDimensions.FirstOrDefault(x => x.RiskFactorDimensionID == dimension.RiskFactorDimensionID);

            if (dim != null)
            {
                var curveConst = dim.CurveConstituents.FirstOrDefault(x => x.RiskFactorDimItem == item.RiskFactorDimItem);
                if (curveConst != null)
                {
                    if (Context.Entry(curveConst).State == EntityState.Added)
                    {
                        // safely remove item is not persisted
                        Context.CurveConstituents.Remove(curveConst);
                    }
                    else
                    {
                        curveConst.Expire(Context.UserName);
                        curveConst.Latest = false;
                    }
                }
                if (dim.CurveConstituents.Where(x => x.Status != EntityStatus.ExpiredInSession).Count() == 0)
                {
                    dim.IsSelected = false;
                }
            }
        }