예제 #1
0
 /// <summary>
 /// Saves all dirty objects inside the enumeration passed to the persistent storage.
 /// </summary>
 /// <param name="entitiesToSave">The entities to save.</param>
 /// <param name="dataAccessAdapter">The data access adapter.</param>
 /// <returns>the amount of persisted entities</returns>
 public static int SaveEntities(IEnumerable entitiesToSave, IDataAccessAdapter dataAccessAdapter)
 {
     if (entitiesToSave is IEntityCollection2)
     {
         return(dataAccessAdapter.SaveEntityCollection((IEntityCollection2)entitiesToSave));
     }
     return(SaveEntities(entitiesToSave.Cast <IEntity2>(), dataAccessAdapter));
 }
예제 #2
0
        public bool SaveHostImages(long hostId, List <HostImage> hostImages)
        {
            EntityCollection <FileEntity> fileEntities = new EntityCollection <FileEntity>();

            hostImages.ForEach(hostImage =>
            {
                var hostImageEntities = new EntityCollection <HostImageEntity>();
                hostImageEntities.Add(new HostImageEntity()
                {
                    HostId        = hostId,
                    IsNew         = true,
                    HostImageType = hostImage.ImageType.PersistenceLayerId
                });

                // TODO: To move this code in the mapper class. Currently in QA branch, will do in main trunk.
                fileEntities.Add(new FileEntity(0)
                {
                    Path        = hostImage.Path,
                    Size        = hostImage.FileSize,
                    Type        = (long)hostImage.Type,
                    CreatedDate = DateTime.Now,
                    CreatedBy   = hostImage.UploadedBy.Id,
                    IsNew       = true
                });

                fileEntities.Last().HostImage.AddRange(hostImageEntities);
            });

            using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                if (myAdapter.SaveEntityCollection(fileEntities, false, true) <= 0)
                {
                    throw new PersistenceFailureException();
                }
            }

            return(true);
        }
예제 #3
0
 protected void ExpectSaveEntityCollection(int numberOfEntitiesSaved)
 {
     Expect.Call(_dataAccessAdapter.SaveEntityCollection(null)).IgnoreArguments().Return(numberOfEntitiesSaved);
 }