/// <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(); }
public async Task <IActionResult> Save(GalleryEditorViewModel viewModel) { if (galleryValidator.isValid(viewModel)) { galleryRepository.Save(viewModel.Id, viewModel.Label); return(Redirect("~/")); } viewModel.Message = galleryValidator.GetMessage(); return(View("Editor", viewModel)); }
/// <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(); }
/// <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(); }
/// <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(); }