public virtual void DeleteShopImage(ShopImage shopImage) { ISession session = this._sessionManager.OpenSession(); NHibernate.ITransaction tx = session.BeginTransaction(); try { session.Delete(shopImage); tx.Commit(); session.Close(); } catch (Exception ex) { tx.Rollback(); throw new Exception("Unable to delete Shop image" + "<br>" + ex.Message + "<br>" + ex.InnerException, ex); } }
private ShopImage SaveAttachment(ShopProduct product, FileUpload file) { ShopImage imgProductImage = new ShopImage(); if(file.PostedFile == null || file.PostedFile.FileName.Trim().Length==0 || file.PostedFile.ContentLength==0) return null; string filename = file.PostedFile.FileName; imgProductImage.OrigImageName = filename; imgProductImage.ShopImageName = filename; imgProductImage.ImageSize = file.PostedFile.ContentLength; imgProductImage.ContentType = file.PostedFile.ContentType; imgProductImage.ProductId = product.Id; imgProductImage.Data = file.FileBytes; try { this._module.SaveShopImage(imgProductImage); } catch(Exception ex) { throw new Exception("Unable to save image ",ex); } return imgProductImage; }
private ShopImage SaveAttachment(ShopProduct product, HtmlInputFile file) { ShopImage imgProductImage = new ShopImage(); if(file.PostedFile==null || file.PostedFile.FileName.Trim().Length==0 || file.PostedFile.ContentLength==0) return null; string sUpDir = Server.MapPath(UrlHelper.GetApplicationPath() + "/Modules/Shop/Attach/"); string filename = file.PostedFile.FileName; if(!System.IO.Directory.Exists(sUpDir)) { System.IO.Directory.CreateDirectory(sUpDir); } int pos = filename.LastIndexOfAny(new char[]{'/','\\'}); if (pos >= 0) filename = filename.Substring(pos+1); string newfilename = String.Format("{0}{1}.{2}.{3}", sUpDir, this._shopShop.Id , product.Id, filename); file.PostedFile.SaveAs(newfilename); imgProductImage.OrigImageName = filename; imgProductImage.ShopImageName = newfilename; imgProductImage.ImageSize = file.PostedFile.ContentLength; imgProductImage.ContentType = file.PostedFile.ContentType; imgProductImage.ProductId = product.Id; try { this._module.SaveShopImage(imgProductImage); } catch(Exception ex) { throw new Exception("Unable to save image ",ex); } return imgProductImage; }