Exemplo n.º 1
0
 public OneDimVisualizationController(RiskFactorDimItemDetail[] items, RiskFactorDimension dim, List<ScenarioPointCoordinate> points)
 {
     list = new List<OneDimCoordinate>();
     Array.Sort(items); // first coordinate
     DimItems = items;
     Points = new List<ScenarioPointCoordinate>(points);
     Create();
 }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
        public RiskFactorDimItemDetail AddRiskFactorDimItem()
        {
            var record = new RiskFactorDimItem();
            var detail = new RiskFactorDimItemDetail();
            record.RiskFactorDimItemDetails.Add(detail);
            detail.RiskFactorDimItem = record;
            detail.Default(Context.UserName);
            record.Default(Context.UserName);

            detail.Name = "Risk Factor Dim Item";
            if (Context.RiskFactorDimItemDetails.Local.Count() > 0)
            {
                detail.RiskFactorDimItemDetailID = Context.RiskFactorDimItemDetails.Local.Max(x => x.RiskFactorDimItemDetailID) + 1;
            }
            else
            {
                detail.RiskFactorDimItemDetailID = 1;
            }
            Context.RiskFactorDimItemDetails.Add(detail);
            return detail;
        }
Exemplo n.º 4
0
        protected override void BeforeSave()
        {
            DateTime timestamp = DateTime.UtcNow;

            //find all changed enities
            var modifiedEntities = Context.ChangeTracker.Entries<RiskFactorDimItemDetail>()
                    .Where(p => p.State == EntityState.Modified)
                    .Select(p => p.Entity);

            foreach (RiskFactorDimItemDetail detail in modifiedEntities)
            {
                //main entity, for which we keep versioning
                var mainEntity = detail.RiskFactorDimItem;
                ICollection<RiskFactorDimItemDetail> mainEntityDetails = mainEntity.RiskFactorDimItemDetails;

                if (detail.Status == EntityStatus.ExpiredInSession)
                {
                    foreach (RiskFactorDimItemDetail item in mainEntityDetails)
                    {
                        if (detail.RiskFactorDimItemDetailID != item.RiskFactorDimItemDetailID)
                        {
                            item.EndTime = detail.EndTime;
                            item.ModifiedBy = detail.ModifiedBy;
                            item.ModifiedAt = detail.ModifiedAt;
                        }
                    }

                    mainEntity.EndTime = detail.EndTime;
                    mainEntity.ModifiedBy = detail.ModifiedBy;
                    mainEntity.ModifiedAt = detail.ModifiedAt;
                }

                if (detail.Status == EntityStatus.ApprovedInSession)
                {
                    //entity has been approved
                    //mark existing details as expired
                    foreach (RiskFactorDimItemDetail item in mainEntityDetails)
                    {
                        if (detail.RiskFactorDimItemDetailID != item.RiskFactorDimItemDetailID)
                        {
                            item.Latest = false;
                            item.EndTime = (DateTime)detail.ApprovedAt;
                            detail.StartTime = (DateTime)detail.ApprovedAt;
                        }
                    }

                    //check if main entity is approved - if not copy details
                    if (mainEntity.Status != EntityStatus.Approved)
                    {
                        mainEntity.ApprovedAt = detail.ApprovedAt;
                        mainEntity.ApprovedBy = detail.ApprovedBy;
                        mainEntity.StartTime = detail.StartTime;
                    }
                }
                else if (detail.Status == EntityStatus.UnapprovedInSession)
                {
                    //new version of the entity
                    //we are creating a copy of currently edited entity
                    //and add it back to context

                    var copy = new RiskFactorDimItemDetail();
                    mainEntity.RiskFactorDimItemDetails.Add(copy);
                    //copy values from original
                    Context.Entry(copy).CurrentValues.SetValues(detail);
                    //reset auditing
                    copy.ResetCopy();
                    //revert the changes - done implicitly
                    Context.Entry(detail).State = EntityState.Unchanged;
                    //remove latest flag
                    detail.Latest = false;
                }
            }
        }
Exemplo n.º 5
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;
                }
            }
        }
Exemplo n.º 6
0
 public TwoDimVisualizationController(RiskFactorDimItemDetail[] dimMajorItems, RiskFactorDimension majorDim, RiskFactorDimItemDetail[] dimMinorItems, RiskFactorDimension minorDim, List<ScenarioPointCoordinate> points)
 {
     array2D = new TwoDimCoordinate[dimMajorItems.Length, dimMinorItems.Length];
     Array.Sort(dimMajorItems); // first coordinate
     Array.Sort(dimMinorItems); // second coordinate
     DimMajorItems = dimMajorItems;
     DimMinorItems = dimMinorItems;
     Points = new List<ScenarioPointCoordinate>( points);
     Create();
 }
Exemplo n.º 7
0
        internal static void AddDimItems(ScenarioGeneratorModel context)
        {
            DateTime now = context.AsOfDate;
            var riskFactorDimType = context.RiskFactorDimTypes.Where(x => x.Name == "Tenor").First();

            var main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            var detail = new RiskFactorDimItemDetail() { Name = "1D", Ordinal = 1,  StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "2D", Ordinal=2, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "3D", Ordinal = 3, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "4D", Ordinal = 4, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "5D", Ordinal = 5, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "1W", Ordinal = 7, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            riskFactorDimType = context.RiskFactorDimTypes.Where(x => x.Name == "Currency").First();
            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "EUR", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "GBP", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "USD", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "AUD", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "JPY", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "HKD", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "TWD", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "PLN", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            riskFactorDimType = context.RiskFactorDimTypes.Where(x => x.Name == "Country").First();

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "France", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "Germany", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "Italy", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "Spain", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() {  Name = "Portugal", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            context.SaveChanges();
        }