public bool Update(Book book, IFormFile image, IFormFile pdf) { base.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted); var fileBO = new FileBO(); try { if (image != null) { if (book.Image != null) { if (!fileBO.Delete(base.ConnectionHandler, book.Image)) { throw new Exception("خطایی در درج اطلاعات کتاب رخ داده است"); } } var imageId = fileBO.Insert(base.ConnectionHandler, image, book.ImageFile); if (imageId == null && imageId == Guid.Empty) { throw new Exception("خطایی در درج اطلاعات کتاب رخ داده است"); } book.Image = imageId; } if (pdf != null) { var exte = Path.GetExtension(pdf.FileName).ToLower(); if (Path.GetExtension(pdf.FileName).ToLower() != ".pdf") { throw new Exception("فایل بارگزاری شده برای کتاب باید با پسوند pdf باشد"); } if (book.PDF != null) { if (!fileBO.Delete(base.ConnectionHandler, book.PDF)) { throw new Exception("خطایی در درج اطلاعات کتاب رخ داده است"); } } var pdfId = fileBO.Insert(base.ConnectionHandler, pdf, book.PdfFile); if (pdfId == null && pdfId == Guid.Empty) { throw new Exception("خطایی در درج اطلاعات کتاب رخ داده است"); } book.PDF = pdfId; } if (!new BookBO().Update(base.ConnectionHandler, book)) { throw new Exception("خطایی در درج اطلاعات کتاب رخ داده است"); } base.ConnectionHandler.CommitTransaction(); return(true); } catch (Exception ex) { base.ConnectionHandler.RollBack(); throw new Exception(ex.Message, ex); } }
public bool Delete(Guid id) { base.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted); var fileBO = new FileBO(); var bookPartBO = new BookPartBO(); try { var bookPart = bookPartBO.Get(base.ConnectionHandler, id); if (bookPart.Image != null && bookPart.Image != Guid.Empty) { if (!fileBO.Delete(base.ConnectionHandler, bookPart.Image)) { throw new Exception("خطایی در حذف اطلاعات کتاب رخ داده است"); } } if (!bookPartBO.Delete(base.ConnectionHandler, bookPart)) { throw new Exception("خطایی در حذف اطلاعات کتاب رخ داده است"); } base.ConnectionHandler.CommitTransaction(); return(true); } catch (Exception ex) { base.ConnectionHandler.RollBack(); throw new Exception(ex.Message, ex); } }
public override bool Update(BookPart bookPart) { base.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted); var fileBO = new FileBO(); try { var file = new File() { Content = bookPart.Text.ConvertTextToHtml(), Extension = ".png", ContentType = "image/png", FileName = bookPart.Name, }; if (bookPart.Image != null) { if (!fileBO.Delete(base.ConnectionHandler, bookPart.Image)) { throw new KnownException("خطایی در درج اطلاعات کتاب رخ داده است"); } } var imageId = fileBO.InsertFile(base.ConnectionHandler, file); if (imageId == null && imageId == Guid.Empty) { throw new KnownException("خطایی در درج اطلاعات کتاب رخ داده است"); } bookPart.Image = imageId; if (!new BookPartBO().Update(base.ConnectionHandler, bookPart)) { throw new KnownException("خطایی در درج اطلاعات کتاب رخ داده است"); } base.ConnectionHandler.CommitTransaction(); return(true); } catch (Exception ex) { base.ConnectionHandler.RollBack(); throw new KnownException(ex.Message, ex); } }