public void DeleteImageById(int ImageId) { PROD_IMAGES img = new PROD_IMAGES() { ID = ImageId }; Context.PROD_IMAGES.Attach(img); Context.PROD_IMAGES.DeleteObject(img); }
private void loadImages(PRODUCT product) { if (product.PROD_IMAGES != null && product.PROD_IMAGES.Count > 0) { PROD_IMAGES principalImage = product.PROD_IMAGES.Where(i => i.Principal.HasValue && i.Principal.Value).FirstOrDefault(); imgProdBig.ImageUrl = Configuration.ImagesUploadPath + principalImage.Image; lnkImage.HRef = Configuration.ImagesUploadPath + principalImage.LargeImage; hdnPreviousImage.Value = principalImage.ID.ToString(); rptImages.DataSource = product.PROD_IMAGES.OrderByDescending(i => i.Principal); rptImages.DataBind(); } }
private PROD_IMAGES createEmptyImage() { PROD_IMAGES fake = new PROD_IMAGES() { ID = 0, Image = String.Empty, LargeImage = String.Empty, Principal = false, ProductID = Int32.Parse(ID.Value), Thumbnail = String.Empty }; return(fake); }
private void setImages(PRODUCT product, FZExcelProduct exProd, string encryptedCampId) { string startFolder = Configuration.ImagesUploadPath + "\\" + encryptedCampId; // Take a snapshot of the file system. System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(startFolder); IEnumerable <System.IO.FileInfo> fileList = dir.GetFiles("*.*", System.IO.SearchOption.AllDirectories); //Create the query IEnumerable <System.IO.FileInfo> fileQuery = from file in fileList where file.Name.ToLower().Contains(exProd.Code.ToLower()) orderby file.Name select file; //Execute the query PROD_IMAGES img; int count = 0; foreach (System.IO.FileInfo fi in fileQuery) { img = new PROD_IMAGES() { ProductID = product.ID, Image = "MED" + fi.Name, LargeImage = fi.Name, Thumbnail = "SMALL" + fi.Name, Principal = false }; if (count == 0) { img.Principal = true; } fi.CopyTo(System.IO.Path.Combine(Configuration.ImagesUploadPath + fi.Name)); // physical saving of all image versions GraphicsUtil.SaveProductImages(fi.Name, img.Principal.Value); InsertImage(img); Console.WriteLine(fi.FullName); count++; } }
public void Save() { if (String.IsNullOrEmpty(oldImg.Value) || oldImg.Value != LargeImage) { PROD_IMAGES image = new PROD_IMAGES(); image.Image = Image; image.Principal = Principal; image.LargeImage = LargeImage; image.Thumbnail = Thumbnail; image.ProductID = Int32.Parse(ProdID); int id = 0; lblErrors.Visible = true; lblErrors.ForeColor = Color.Green; string operation = String.Empty; try { GraphicsUtil.SaveProductImages(LargeImage, Principal); // TODO the following code should be removed as it was encapsulated in the GraphicsUtil.SaveProductImages method //string fileWithPath = Path.Combine(Configuration.ImagesUploadPath, LargeImage); //string thumbWithPath = Path.Combine(Configuration.ImagesUploadPath, Thumbnail); //System.Drawing.Image img = System.Drawing.Image.FromFile(fileWithPath); //FileInfo fi2 = new FileInfo(thumbWithPath); //if (!fi2.Exists) //{ // using (System.Drawing.Image imgResized = GraphicsUtil.ResizeProductImage(img, ImageType.Small)) // { // imgResized.Save(thumbWithPath); // } //} //string mediumWithPath = Path.Combine(Configuration.ImagesUploadPath, Image); //fi2 = new FileInfo(mediumWithPath); //if (!fi2.Exists) //{ // using (System.Drawing.Image imgResized = GraphicsUtil.ResizeProductImage(img, ImageType.Medium)) // { // imgResized.Save(mediumWithPath); // } //} //if (Principal && !String.IsNullOrEmpty(image.Image)) //{ // //string fileWithPath = Path.Combine(Server.MapPath(Configuration.ImagesUploadPath), image.Image); // //string fileListWithPath = Path.Combine(Server.MapPath(Configuration.ImagesUploadPath), "LIST" + image.Image); // string fileListWithPath = Path.Combine(Configuration.ImagesUploadPath, "LIST" + image.LargeImage); // FileInfo fi = new FileInfo(fileListWithPath); // if (!fi.Exists) // { // using (System.Drawing.Image imgResized = GraphicsUtil.ResizeProductImage(img, ImageType.List)) // { // imgResized.Save(fileListWithPath); // } // } //} //img.Dispose(); //img = null; if (!String.IsNullOrWhiteSpace(ImgID) && Int32.TryParse(ImgID, out id) && id != 0) { image.ID = id; ApplicationContext.Current.Products.UpdateImage(image); operation = "updated"; } else { ApplicationContext.Current.Products.InsertImage(image); operation = "inserted"; ImgID = image.ID.ToString(); } lblErrors.Text = "Images " + operation + " correctly."; oldImg.Value = LargeImage; if (!String.IsNullOrEmpty(Page.User.Identity.Name)) { USER user = ApplicationContext.Current.Users.GetByUserName(Page.User.Identity.Name); // not an administrator neither a moderator if (user.RoleID <= 2) { lnkDelete.Visible = true; } } } catch (Exception ex) { // TODO log error lblErrors.ForeColor = Color.Red; lblErrors.Text = "Error occurred: " + ex.Message; } } }
public void InsertImage(PROD_IMAGES Image) { Context.PROD_IMAGES.AddObject(Image); }
public void UpdateImage(PROD_IMAGES Image) { Context.PROD_IMAGES.AddObject(Image); Context.ObjectStateManager.ChangeObjectState(Image, EntityState.Modified); }
public void InsertImage(PROD_IMAGES Image) { _productDAO.InsertImage(Image); Context.SaveChanges(); }
public void UpdateImage(PROD_IMAGES Image) { _productDAO.UpdateImage(Image); Context.SaveChanges(); }