Esempio n. 1
0
        //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;
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        public void TestSaveRiskFactorType()
        {
            string name = "Risk Factor Test Name";
            RiskFactorType main;
            RiskFactorTypeDetail detail;
            RiskFactorTypeGroup group;

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                group = context.RiskFactorTypeGroups.Find(2);

                main = new RiskFactorType();
                main.Default(UserName);
                context.RiskFactorTypes.Add(main);
                detail = new RiskFactorTypeDetail();
                detail.Default(UserName);
                main.RiskFactorTypeDetails.Add(detail);
                detail.Name = name;
                detail.RiskFactorTypeGroupID = group.RiskFactorTypeGroupID;

                context.SaveChanges();
            }

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                detail = context.RiskFactorTypeDetails.Where(a => a.Name == name).FirstOrDefault();
                Assert.AreEqual(name, detail.Name);
                Assert.AreEqual(true, detail.Latest);
                Assert.AreEqual(DateTime.MinValue, detail.StartTime);
                Assert.AreEqual(DateTime.MaxValue, detail.EndTime);
                Assert.AreEqual(EntityStatus.Unapproved, detail.Status);

                main = detail.RiskFactorType;
                Assert.AreEqual(true, main.Latest);
                Assert.AreEqual(DateTime.MinValue, main.StartTime);
                Assert.AreEqual(DateTime.MaxValue, main.EndTime);
                Assert.AreEqual(DateTime.MaxValue, main.EndTime);
                Assert.AreEqual(EntityStatus.Unapproved, main.Status);

            }
        }
Esempio n. 5
0
        protected override void BeforeSave()
        {
            DateTime timestamp = DateTime.UtcNow;

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

            foreach (RiskFactorTypeDetail detail in modifiedEntities)
            {
                //main entity, for which we keep versioning
                RiskFactorType mainEntity = detail.RiskFactorType;
                ICollection<RiskFactorTypeDetail> mainEntityDetails = mainEntity.RiskFactorTypeDetails;

                if (detail.Status == EntityStatus.ExpiredInSession)
                {
                    foreach (RiskFactorTypeDetail item in mainEntityDetails)
                    {
                        if (detail.RiskFactorTypeDetailID != item.RiskFactorTypeDetailID)
                        {
                            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 (RiskFactorTypeDetail item in mainEntityDetails)
                    {
                        if (detail.RiskFactorTypeDetailID != item.RiskFactorTypeDetailID)
                        {
                            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;
                    }

                    // approve all consituents
                    foreach (var dim in mainEntity.RiskFactorTypeDimensions)
                    {
                        if (dim.Status != EntityStatus.Unapproved || dim.Status != EntityStatus.UnapprovedInSession)
                        {
                            dim.ApprovedAt = detail.ApprovedAt;
                            dim.ApprovedBy = detail.ApprovedBy;
                            dim.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

                    RiskFactorTypeDetail copy = new RiskFactorTypeDetail();

                    mainEntity.RiskFactorTypeDetails.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;

                }
            }
        }