public bool Insert(DataStructure.News news, NewsContent content, NewsProperty property, HttpPostedFileBase fileBase) { try { this.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted); this.FileManagerConnection.StartTransaction(IsolationLevel.ReadUncommitted); if (fileBase != null) { news.ThumbnailId = FileManagerComponent.Instance.FileTransactionalFacade(this.FileManagerConnection) .Insert(fileBase); } if (!new NewsBO().Insert(this.ConnectionHandler, news)) { throw new Exception("خطایی در ذخیره اخبار وجود دارد"); } if (content != null) { content.Id = news.Id; if (!new NewsContentBO().Insert(this.ConnectionHandler, content)) { throw new Exception("خطایی در ذخیره محتوای اخبار وجود دارد"); } } if (property != null) { property.Id = news.Id; if (!new NewsPropertyBO().Insert(this.ConnectionHandler, property)) { throw new Exception("خطایی در ذخیره تنظیمات اخبار وجود دارد"); } } this.ConnectionHandler.CommitTransaction(); this.FileManagerConnection.CommitTransaction(); return(true); } catch (KnownException ex) { this.ConnectionHandler.RollBack(); this.FileManagerConnection.RollBack(); Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } catch (Exception ex) { this.ConnectionHandler.RollBack(); this.FileManagerConnection.RollBack(); Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } }
public override bool Update(IConnectionHandler connectionHandler, DataStructure.News obj) { if (!base.Update(connectionHandler, obj)) { return(false); } var oldobj = this.Get(connectionHandler, obj.Id); if (oldobj.ThumbnailId.HasValue && obj.ThumbnailId == null) { FileManagerComponent.Instance.FileFacade.Delete(oldobj.ThumbnailId); } return(true); }
public bool Update(DataStructure.News obj, NewsContent content, NewsProperty property, HttpPostedFileBase fileBase) { try { this.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted); this.FileManagerConnection.StartTransaction(IsolationLevel.ReadUncommitted); if (fileBase != null) { if (obj.ThumbnailId.HasValue && property.HasAttachment) { FileManagerComponent.Instance.FileTransactionalFacade(this.FileManagerConnection) .Update(fileBase, obj.ThumbnailId.Value); } else { obj.ThumbnailId = FileManagerComponent.Instance.FileTransactionalFacade(this.FileManagerConnection) .Insert(fileBase); } } if (property != null) { if (!new NewsPropertyBO().Update(this.ConnectionHandler, property)) { throw new Exception("خطایی در ویرایش تنظیمات خبر وجود دارد"); } } if (content != null) { if (content.Id == 0) { content.Id = obj.Id; if (!new NewsContentBO().Insert(this.ConnectionHandler, content)) { throw new Exception("خطایی در ذخیره محتوای اخبار وجود دارد"); } } else { if (!new NewsContentBO().Update(this.ConnectionHandler, content)) { throw new Exception("خطایی در ویرایش محتوای اخبار وجود دارد"); } } } if (!new NewsBO().Update(this.ConnectionHandler, obj)) { throw new Exception("خطایی در ویرایش اخبار وجود دارد"); } this.ConnectionHandler.CommitTransaction(); this.FileManagerConnection.CommitTransaction(); return(true); } catch (KnownException ex) { this.ConnectionHandler.RollBack(); this.FileManagerConnection.RollBack(); Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } catch (Exception ex) { this.ConnectionHandler.RollBack(); this.FileManagerConnection.RollBack(); Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } }