public void ExpireMembers(RiskFactorDimItemGroup group)
 {
     foreach(RiskFactorDimItemGroupMember member in group.RiskFactorDimItemGroupMembers)
     {
         member.Expire(Context.UserName);
     }
 }
        public void RemoveGroupMember(RiskFactorDimItem item, RiskFactorDimItemGroup group)
        {
            //check if entity of this characteristic already exists
            var persisted = group.RiskFactorDimItemGroupMembers.Where(x => x.RiskFactorDimItem.RiskFactorDimItemID == item.RiskFactorDimItemID).FirstOrDefault();

            if (persisted != null && Context.Entry(persisted).State == EntityState.Added)
            {
                // safely remove item is not persisted
                group.RiskFactorDimItemGroupMembers.Remove(persisted);
                Context.RiskFactorDimItemGroupMembers.Remove(persisted);
            }
            else
            {
                persisted.Expire(Context.UserName);
                persisted.Latest = false;
            }
        }
        public RiskFactorDimItemGroup Add()
        {
            RiskFactorDimItemGroup group = new RiskFactorDimItemGroup();
            group.Default(Context.UserName);
            group.Approve(Context.UserName);

            if (Context.RiskFactorDimItemGroups.Local.Any())
                group.RiskFactorDimItemGroupID = Context.RiskFactorDimItemGroups.Local.Max(x => x.RiskFactorDimItemGroupID) + 1;
            else
                group.RiskFactorDimItemGroupID = 1;

            Context.RiskFactorDimItemGroups.Add(group);

            group.Name = "Risk Factor Dim Group Name";

            return group;
        }
        public RiskFactorDimItemGroupMember AddGroupMember(RiskFactorDimItem item, RiskFactorDimItemGroup group)
        {
            //check if entity of this characteristic already exists
            var persisted = group.RiskFactorDimItemGroupMembers.Where(x => x.RiskFactorDimItem.RiskFactorDimItemID == item.RiskFactorDimItemID).FirstOrDefault();

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

            var member = new RiskFactorDimItemGroupMember();
            member.Default(Context.UserName);
            member.RiskFactorDimItem = item;
            item.RiskFactorDimItemGroupMembers.Add(member);

            member.RiskFactorDimItemGroup = group;
            group.RiskFactorDimItemGroupMembers.Add(member);

            return member;
        }