예제 #1
0
        /// <summary>
        /// Persist this gallery object to the data store.
        /// </summary>
        public void Save()
        {
            bool isNew = IsNew;

            using (var repo = new GalleryRepository())
            {
                if (IsNew)
                {
                    var galleryDto = new GalleryDto {
                        Description = Description, DateAdded = CreationDate
                    };
                    repo.Add(galleryDto);
                    repo.Save();
                    _id = galleryDto.GalleryId;
                }
                else
                {
                    var galleryDto = repo.Find(GalleryId);

                    if (galleryDto != null)
                    {
                        galleryDto.Description = Description;
                        repo.Save();
                    }
                    else
                    {
                        throw new BusinessException(String.Format(CultureInfo.CurrentCulture, "Cannot save gallery: No existing gallery with Gallery ID {0} was found in the database.", GalleryId));
                    }
                }
            }

            // For new galleries, configure it and then trigger the created event.
            if (isNew)
            {
                Configure();

                EventHandler <GalleryCreatedEventArgs> galleryCreated = GalleryCreated;
                if (galleryCreated != null)
                {
                    galleryCreated(null, new GalleryCreatedEventArgs(GalleryId));
                }
            }

            Factory.ClearAllCaches();
        }
예제 #2
0
        /// <summary>
        /// Permanently delete the current gallery from the data store, including all related records. This action cannot
        /// be undone.
        /// </summary>
        public void Delete()
        {
            //Factory.GetDataProvider().Gallery_Delete(this);
            OnBeforeDeleteGallery();

            // Cascade delete relationships should take care of any related records not deleted in OnBeforeDeleteGallery.
            using (var repo = new GalleryRepository())
            {
                var galleryDto = repo.Find(GalleryId);
                if (galleryDto != null)
                {
                    // Delete gallery. Cascade delete rules in DB will delete related records.
                    repo.Delete(galleryDto);
                    repo.Save();
                }
            }

            Factory.ClearAllCaches();
        }
예제 #3
0
        /// <summary>
        /// Persist this gallery instance to the data store.
        /// </summary>
        public void Save()
        {
            bool isNew = IsNew;

            using (var repo = new GalleryRepository())
            {
                if (IsNew)
                {
                    var galleryDto = new GalleryDto {
                        Description = Description, DateAdded = CreationDate
                    };
                    repo.Add(galleryDto);
                    repo.Save();
                    _id = galleryDto.GalleryId;
                }
                else
                {
                    var galleryDto = repo.Find(GalleryId);

                    if (galleryDto != null)
                    {
                        galleryDto.Description = Description;
                        repo.Save();
                    }
                    else
                    {
                        throw new BusinessException(String.Format(CultureInfo.CurrentCulture, "Cannot save gallery: No existing gallery with Gallery ID {0} was found in the database.", GalleryId));
                    }
                }
            }

            // For new galleries, configure it and then trigger the created event.
            if (isNew)
            {
                Validate();

                Factory.ClearGalleryCache(); // Needed so LoadGalleries(), called by AddDefaultRolesToRoleAlbumTable(), pulls new gallery from data store

                AddDefaultRolesToRoleAlbumTable();
            }

            Factory.ClearAllCaches();
        }
예제 #4
0
        /// <summary>
        /// Persist this gallery object to the data store.
        /// </summary>
        public void Save()
        {
            bool isNew = IsNew;

            using (var repo = new GalleryRepository())
            {
                if (IsNew)
                {
                    var galleryDto = new GalleryDto { Description = Description, DateAdded = CreationDate };
                    repo.Add(galleryDto);
                    repo.Save();
                    _id = galleryDto.GalleryId;
                }
                else
                {
                    var galleryDto = repo.Find(GalleryId);

                    if (galleryDto != null)
                    {
                        galleryDto.Description = Description;
                        repo.Save();
                    }
                    else
                    {
                        throw new BusinessException(String.Format(CultureInfo.CurrentCulture, "Cannot save gallery: No existing gallery with Gallery ID {0} was found in the database.", GalleryId));
                    }
                }
            }

            // For new galleries, configure it and then trigger the created event.
            if (isNew)
            {
                Configure();

                EventHandler<GalleryCreatedEventArgs> galleryCreated = GalleryCreated;
                if (galleryCreated != null)
                {
                    galleryCreated(null, new GalleryCreatedEventArgs(GalleryId));
                }
            }

            Factory.ClearAllCaches();
        }
예제 #5
0
        /// <summary>
        /// Permanently delete the current gallery from the data store, including all related records. This action cannot
        /// be undone.
        /// </summary>
        public void Delete()
        {
            //Factory.GetDataProvider().Gallery_Delete(this);
            OnBeforeDeleteGallery();

            // Cascade delete relationships should take care of any related records not deleted in OnBeforeDeleteGallery.
            using (var repo = new GalleryRepository())
            {
                var galleryDto = repo.Find(GalleryId);
                if (galleryDto != null)
                {
                    // Delete gallery. Cascade delete rules in DB will delete related records.
                    repo.Delete(galleryDto);
                    repo.Save();
                }
            }

            Factory.ClearAllCaches();
        }