示例#1
0
        public void AddArchiveStorage(BiblosDS.Library.Common.Objects.DocumentArchiveStorage ArchiveStorage)
        {
            using (Model.BiblosDS2010Entities db = new Model.BiblosDS2010Entities(BiblosDSConnectionString))
            {
                Model.ArchiveStorage entityArchiveStorage = ArchiveStorage.TryToConvertTo <Model.ArchiveStorage>(db);

                if (ArchiveStorage.Storage != null)
                {
                    entityArchiveStorage.IdStorage = ArchiveStorage.Storage.IdStorage;
                    //entityArchiveStorage.StorageReference.TryToAttach(new Model.Storage { IdStorage = ArchiveStorage.Storage.IdStorage }, db);
                }
                else
                {
                    throw new Exceptions.ArchiveStorage_Exception("Storage non valorizzato");
                }

                if (ArchiveStorage.Archive != null)
                {
                    entityArchiveStorage.IdArchive = ArchiveStorage.Archive.IdArchive;
                    //entityArchiveStorage.ArchiveReference.TryToAttach(new Model.Archive { IdArchive = ArchiveStorage.Archive.IdArchive }, db);
                }
                else
                {
                    throw new Exceptions.ArchiveStorage_Exception("Archivio non valorizzato");
                }

                //if (ArchiveStorage. != null)
                //    entityStorage.StorageTypeReference.TryToAttach(new Model.StorageType { IdStorageType = ArchiveStorage.StorageType.IdStorageType }, db);

                db.AddToArchiveStorage(entityArchiveStorage);
                db.SaveChanges();
            }
        }
示例#2
0
 public void DeleteArchiveStorage(BiblosDS.Library.Common.Objects.DocumentArchiveStorage ArchiveStorage)
 {
     using (Model.BiblosDS2010Entities db = new Model.BiblosDS2010Entities(BiblosDSConnectionString))
     {
         var entity = db.ArchiveStorage.Where(x => x.Archive.IdArchive == ArchiveStorage.Archive.IdArchive && x.Storage.IdStorage == ArchiveStorage.Storage.IdStorage).FirstOrDefault();
         if (entity == null)
         {
             throw new Exceptions.ArchiveStorage_Exception();
         }
         db.DeleteObject(entity);
         db.SaveChanges();
     }
 }
示例#3
0
        public void UpdateArchiveStorage(BiblosDS.Library.Common.Objects.DocumentArchiveStorage ArchiveStorage)
        {
            using (Model.BiblosDS2010Entities db = new Model.BiblosDS2010Entities(BiblosDSConnectionString))
            {
                Model.ArchiveStorage entityArchiveStorage = ArchiveStorage.TryToConvertTo <Model.ArchiveStorage>(false);

                //var itemIndB = db.ArchiveStorage.Where(x => x.IdArchive == ArchiveStorage.Archive.IdArchive && x.IdStorage == ArchiveStorage.Storage.IdStorage).First();
                //itemIndB.Active = ArchiveStorage.Active ? (short)1 : (short)0;

                if (ArchiveStorage.Storage != null)
                {
                    entityArchiveStorage.IdStorage = ArchiveStorage.Storage.IdStorage;
                }
                else
                {
                    throw new Exceptions.ArchiveStorage_Exception("Storage non valorizzato");
                }

                if (ArchiveStorage.Archive != null)
                {
                    entityArchiveStorage.IdArchive = ArchiveStorage.Archive.IdArchive;
                }
                else
                {
                    throw new Exceptions.ArchiveStorage_Exception("Archivio non valorizzato");
                }

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

                var attachedEntity = db.GetObjectByKey(entityArchiveStorage.EntityKey) as Model.ArchiveStorage;

                //if (ArchiveStorage.StorageType != null)
                //    entityStorage.StorageTypeReference.TryToAttach(new Model.StorageType { IdStorageType = ArchiveStorage.StorageType.IdStorageType }, attachedEntity.StorageTypeReference, db);

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