public static ProductFeatureApplicability Create(ProductFeature feature, FinancialProduct financialProduct, DateTime today)
        {
            ProductFeatureApplicability applicability = new ProductFeatureApplicability();
            applicability.FinancialProduct = financialProduct;
            applicability.EffectiveDate = today;
            applicability.ProductFeature = feature;

            Context.ProductFeatureApplicabilities.AddObject(applicability);
            return applicability;
        }
        public static ProductFeatureApplicability CreateOrUpdate(ProductFeature feature, FinancialProduct financialProduct, DateTime today)
        {
            ProductFeatureApplicability current = GetActive(feature, financialProduct);
            if (current != null)
                current.EndDate = today;

            ProductFeatureApplicability applicability = new ProductFeatureApplicability();
            applicability.FinancialProduct = financialProduct;
            applicability.EffectiveDate = today;
            applicability.ProductFeature = feature;

            Context.ProductFeatureApplicabilities.AddObject(applicability);
            return applicability;
        }
        public static ProductFeatureApplicability CreateOrUpdate(ProductFeature feature, FinancialProduct financialProduct, decimal? value , DateTime today)
        {
            ProductFeatureApplicability current = GetActive(feature, financialProduct);
            if (current != null && current.Value == value)
                return current;

            bool createNew = (current != null && current.Value != value) || current == null;
            if (current != null && current.Value != value)
                current.EndDate = today;

            if (createNew)
            {
                ProductFeatureApplicability applicability = new ProductFeatureApplicability();
                applicability.FinancialProduct = financialProduct;
                applicability.EffectiveDate = today;
                applicability.ProductFeature = feature;
                applicability.Value = value;

                Context.ProductFeatureApplicabilities.AddObject(applicability);
                return applicability;
            }

            return current;
        }
        public static ProductFeatureApplicability EndActiveAndCreateNew(ProductFeatureApplicability current, DateTime today)
        {
            if (current != null)
                current.EndDate = today;

            ProductFeatureApplicability applicability = new ProductFeatureApplicability();
            applicability.FinancialProduct = current.FinancialProduct;
            applicability.EffectiveDate = today;
            applicability.ProductFeature = current.ProductFeature;

            Context.ProductFeatureApplicabilities.AddObject(applicability);
            return applicability;
        }
        public static ProductFeatureApplicability UpdateFeatureExistence(ProductFeature feature, FinancialProduct financialProduct, bool shouldExist, DateTime today)
        {
            ProductFeatureApplicability current = GetActive(feature, financialProduct);
            //no changes
            if (shouldExist && current != null)
                return current;

            if (shouldExist && current == null)
            {
                ProductFeatureApplicability applicability = new ProductFeatureApplicability();
                applicability.FinancialProduct = financialProduct;
                applicability.EffectiveDate = today;
                applicability.ProductFeature = feature;

                Context.ProductFeatureApplicabilities.AddObject(applicability);
                return applicability;
            }

            if (current != null && shouldExist == false)
            {
                current.EndDate = today;
                return current;
            }

            return null;
        }
 public ProductFeatureApplicabilityModel(ProductFeatureApplicability entity)
 {
     this.Id = entity.Id;
     this.Name = entity.ProductFeature.Name;
 }