public override bool Delete(params object[] keys) { try { this.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted); var obj = new GalleryBO().Get(this.ConnectionHandler, keys); var photos = new PhotoBO().Where(this.ConnectionHandler, photo => photo.GalleryId == obj.Id); var photoFacade = new PhotoFacade(this.ConnectionHandler); foreach (var pic in photos) { if (!photoFacade.Delete(pic.Id)) { throw new Exception("خطایی در حذف عکس وجود دارد"); } } if (!new GalleryBO().Delete(this.ConnectionHandler, keys)) { throw new Exception("خطایی در حذف گالری وجود دارد"); } this.ConnectionHandler.CommitTransaction(); return(true); } catch (KnownException ex) { this.ConnectionHandler.RollBack(); Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } catch (Exception ex) { this.ConnectionHandler.RollBack(); Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } }
public bool AddPicsToGallery(Guid galleryId, List <HttpPostedFileBase> newgalleryPics) { try { var gallery = new GalleryBO().Get(this.ConnectionHandler, galleryId); var photoFacade = new PhotoFacade(this.ConnectionHandler); foreach (var pic in newgalleryPics) { var photo = new Photo(); photo.Title = "Image-" + (newgalleryPics.IndexOf(pic) + 1); photo.UploadDate = gallery.CreateDate; photo.Uploader = gallery.Creator; photo.GalleryId = gallery.Id; if (!photoFacade.Insert(photo, pic)) { throw new Exception("خطایی در ذخیره عکس وجود دارد"); } } return(true); } catch (KnownException ex) { Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } catch (Exception ex) { Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } }
public override bool Delete(params object[] keys) { try { this.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted); this.GalleryConnection.StartTransaction(IsolationLevel.ReadUncommitted); var galleryBo = new GalleryBO(); var obj = galleryBo.Get(this.ConnectionHandler, keys); if (!galleryBo.Delete(this.ConnectionHandler, keys)) { throw new Exception("خطایی در حذف گالری وجود دارد"); } if (!GalleryComponent.Instance.GalleryTransactinalFacade(this.GalleryConnection).Delete(obj.GalleryId)) { throw new Exception("خطایی در حذف گالری وجود دارد"); } this.ConnectionHandler.CommitTransaction(); this.GalleryConnection.CommitTransaction(); return(true); } catch (KnownException knownException) { this.ConnectionHandler.RollBack(); this.GalleryConnection.RollBack(); throw new KnownException(knownException.Message, knownException); } catch (Exception ex) { this.ConnectionHandler.RollBack(); this.GalleryConnection.RollBack(); throw new KnownException(ex.Message, ex); } }