Example #1
0
        public void AddStorageAreaRule(BiblosDS.Library.Common.Objects.DocumentStorageAreaRule StorageAreaRule)
        {
            using (Model.BiblosDS2010Entities db = new Model.BiblosDS2010Entities(BiblosDSConnectionString))
            {
                Model.StorageAreaRule entityStorageAreaRule = StorageAreaRule.TryToConvertTo <Model.StorageAreaRule>(db);

                if (StorageAreaRule.StorageArea != null)
                {
                    entityStorageAreaRule.IdStorageArea = StorageAreaRule.StorageArea.IdStorageArea;
                    //entityStorageAreaRule.StorageAreaReference.TryToAttach(new Model.StorageArea { IdStorageArea = StorageAreaRule.StorageArea.IdStorageArea }, db);
                }
                else
                {
                    throw new Exception("StorageArea non valorizzato");
                }

                if (StorageAreaRule.Attribute != null)
                {
                    entityStorageAreaRule.IdAttribute = StorageAreaRule.Attribute.IdAttribute;
                    //entityStorageAreaRule.AttributesReference.TryToAttach(new Model.Attributes { IdAttribute = StorageAreaRule.Attribute.IdAttribute }, db);
                }
                else
                {
                    throw new Exception("Attribute non valorizzato");
                }

                if (StorageAreaRule.RuleOperator != null)
                {
                    entityStorageAreaRule.IdRuleOperator = StorageAreaRule.RuleOperator.IdRuleOperator;
                }

                db.AddToStorageAreaRule(entityStorageAreaRule);
                db.SaveChanges();
            }
        }
Example #2
0
        public void UpdateStorageAreaRule(BiblosDS.Library.Common.Objects.DocumentStorageAreaRule StorageAreaRule)
        {
            using (Model.BiblosDS2010Entities db = new Model.BiblosDS2010Entities(BiblosDSConnectionString))
            {
                Model.StorageAreaRule entityStorageAreaRule = StorageAreaRule.TryToConvertTo <Model.StorageAreaRule>(db);

                if (StorageAreaRule.StorageArea != null)
                {
                    entityStorageAreaRule.IdStorageArea = StorageAreaRule.StorageArea.IdStorageArea;
                }
                else
                {
                    throw new Exception("StorageArea non valorizzato");
                }

                if (StorageAreaRule.Attribute != null)
                {
                    entityStorageAreaRule.IdAttribute = StorageAreaRule.Attribute.IdAttribute;
                }
                else
                {
                    throw new Exception("Attribute non valorizzato");
                }

                if (StorageAreaRule.RuleOperator != null)
                {
                    entityStorageAreaRule.IdRuleOperator = StorageAreaRule.RuleOperator.IdRuleOperator;
                }

                if (entityStorageAreaRule.EntityKey == null)
                {
                    entityStorageAreaRule.EntityKey = db.CreateEntityKey(entityStorageAreaRule.GetType().Name, entityStorageAreaRule);
                }

                var attachedEntity = db.GetObjectByKey(entityStorageAreaRule.EntityKey) as Model.StorageAreaRule;

                db.ApplyCurrentValues(entityStorageAreaRule.EntityKey.EntitySetName, entityStorageAreaRule);
                db.SaveChanges();
            }
        }