Exemple #1
0
        public void AddStorageRule(BiblosDS.Library.Common.Objects.DocumentStorageRule StorageRule)
        {
            using (Model.BiblosDS2010Entities db = new Model.BiblosDS2010Entities(BiblosDSConnectionString))
            {
                Model.StorageRule entityStorageRule = StorageRule.TryToConvertTo <Model.StorageRule>(db);

                if (StorageRule.Storage != null)
                {
                    entityStorageRule.IdStorage = StorageRule.Storage.IdStorage;
                    //entityStorageRule.StorageReference.TryToAttach(new Model.Storage { IdStorage = StorageRule.Storage.IdStorage }, db);
                }
                else
                {
                    throw new Exception("Storage non valorizzato");
                }

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

                if (StorageRule.RuleOperator != null)
                {
                    entityStorageRule.IdRuleOperator = StorageRule.RuleOperator.IdRuleOperator;
                }

                db.AddToStorageRule(entityStorageRule);
                db.SaveChanges();
            }
        }
Exemple #2
0
        public void UpdateStorageRule(BiblosDS.Library.Common.Objects.DocumentStorageRule StorageRule)
        {
            using (Model.BiblosDS2010Entities db = new Model.BiblosDS2010Entities(BiblosDSConnectionString))
            {
                Model.StorageRule entityStorageRule = StorageRule.TryToConvertTo <Model.StorageRule>(db);

                if (StorageRule.Storage != null)
                {
                    entityStorageRule.IdStorage = StorageRule.Storage.IdStorage;
                    //entityStorageRule.StorageReference.TryToAttach(new Model.Storage { IdStorage = StorageRule.Storage.IdStorage }, db);
                }
                else
                {
                    throw new Exception("Storage non valorizzato");
                }

                if (StorageRule.Attribute != null)
                {
                    entityStorageRule.IdAttribute = StorageRule.Attribute.IdAttribute;
                    //entityStorageRule.AttributesReference.TryToAttach(new Model.Archive { IdArchive = StorageRule.Attribute.IdAttribute }, db);
                }
                else
                {
                    throw new Exception("Attribute non valorizzato");
                }

                if (entityStorageRule.EntityKey == null)
                {
                    entityStorageRule.EntityKey = db.CreateEntityKey(entityStorageRule.GetType().Name, entityStorageRule);
                }
                var attachedEntity = db.GetObjectByKey(entityStorageRule.EntityKey) as Model.StorageRule;

                if (StorageRule.RuleOperator != null)
                {
                    entityStorageRule.IdRuleOperator = StorageRule.RuleOperator.IdRuleOperator;
                }

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