public void DeleteImage(int IdImage) { ImagesProduct ImagToDelete = db.ImagesProduct.Find(IdImage); db.ImagesProduct.Remove(ImagToDelete); db.SaveChanges(); }
public void AddImages(Product product, List <HttpPostedFileBase> File) { foreach (var item in File) { if (item != null && item.ContentLength > 0) { if (Path.GetExtension(item.FileName).ToLower() == ".gif" || Path.GetExtension(item.FileName).ToLower() == ".jpg" || Path.GetExtension(item.FileName).ToLower() == ".png" || Path.GetExtension(item.FileName).ToLower() == ".jpeg" ) { ImagesProduct images = new ImagesProduct(); var id = db.Products.SingleOrDefault(x => x.Title == product.Title).Id; var imgCount = db.ImagesProducts.Where(x => x.ProductId == id).Count(); if (imgCount + File.Count <= 5) { images.ProductId = id; images.ImagePath = Path.Combine(Directory.GetCurrentDirectory(), @"/Images/", item.FileName); db.ImagesProducts.Add(images); db.SaveChanges(); } string fileName = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Images/"), item.FileName); item.SaveAs(fileName); } } } }
public ActionResult AddImage(AddImageVM imageVM) { string uniqueFileName = null; if (imageVM.imageFile != null) { try { string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + imageVM.imageFile.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { imageVM.imageFile.CopyTo(fileStream); } ImagesProduct images = new ImagesProduct(); images.ImagesString = uniqueFileName; images.ProductId = imageVM.id; context.AddImage(images); var idManhal = context.GetManahel(imageVM.id).Id; return(RedirectToAction(nameof(Index), "Product", new { manhalID = idManhal })); } catch { } } return(View(imageVM)); }
//dlelte image public ActionResult DeleteImage(int id) { ImagesProduct DletedImage = db.ImagesProduct.FirstOrDefault(Image => Image.ID == id); int productId = DletedImage.ProductObject.ProductId; Product myproduct = db.Product.FirstOrDefault(p => p.ProductId == productId); db.ImagesProduct.Remove(DletedImage); db.SaveChanges(); return(RedirectToAction("ImagesUpdate", new { id = myproduct.ProductId })); }
public bool InsertarImagen(Images obj) { var capData = new Shoes_Data.CapaData(); ImagesProduct Iproduct = new ImagesProduct(); Iproduct.IdProduct = obj.idProducto; Iproduct.Image = obj.Image; Iproduct.Decription = obj.Descripcion; Iproduct.DateUpdate = obj.DateUpdate; Iproduct.IsEnabled = obj.isEnabled; var estado = capData.InsertImages(Iproduct); return(estado); }
public void AddImage(byte[] img, int id) { ImagesProduct Img = new ImagesProduct() { IdImageProduct = id, Decription = "Image of product", Image = img, DateUpdate = DateTime.Now + "", IsEnabled = "true", }; var data = new Data.CapaData(); data.SaveImage(Img); }
public void AddImage(byte[] img, int id) { ImagesProduct ImagReg = new ImagesProduct() { IdImageProduct = id, //id, Decription = "Image of product " + id, Image = img, DateUpdate = DateTime.Now + "", IsEnabled = "true", }; db.ImagesProduct.Add(ImagReg); db.SaveChanges(); }
public static void RegistraImagen(int idP, string desc, byte[] img, string dateUp, int enable) { var context = new DataProductsEntities(); var imgpro = new ImagesProduct { IdProduct = idP, Decription = desc, Image = img, DateUpdate = Convert.ToDateTime(dateUp), IsEnabled = Convert.ToBoolean(enable) }; context.ImagesProduct.Add(imgpro); context.SaveChanges(); }
public ActionResult AddProduct() { var category = categoryService.GetAll(); var product = new Product(); var Images = new ImagesProduct(); AddProductViewModel vm = new AddProductViewModel { Categories = category, Product = product, ImagesProduct = Images }; return(View(vm)); }
public ActionResult EditProduct(int productId) { var product = productService.GetById(productId); var categories = categoryService.GetAll(); var images = new ImagesProduct(); AddProductViewModel vm = new AddProductViewModel { Product = product, Categories = categories, ImagesProduct = images }; return(View(vm)); }
public void DeleteImage(int idImage) { ImagesProduct img = context.ImagesProducts.Where(a => a.Id == idImage).FirstOrDefault(); try { string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images"); var path = System.IO.Path.Combine(Directory.GetCurrentDirectory(), uploadsFolder, img.ImagesString); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } } catch { } context.ImagesProducts.Remove(img); context.SaveChanges(); }
public ActionResult UploadFiles(HttpPostedFileBase[] files, int ProductId) { ImagesProduct ImageProductObject; //Ensure model state is valid if (ModelState.IsValid) { //iterating through multiple file collection foreach (HttpPostedFileBase file in files) { //Checking file is available to save. if (file != null) { var InputFileName = Path.GetFileName(file.FileName); var ServerSavePath = Path.Combine(Server.MapPath("~/Content/images/PoductImages/") + InputFileName); string filePath = "/Content/images/PoductImages/" + InputFileName; //Save file to server folder file.SaveAs(ServerSavePath); //assigning file uploaded status to ViewBag for showing message to user. ViewBag.UploadStatus = files.Count().ToString() + " files uploaded successfully."; ImageProductObject = new ImagesProduct { ImagesUrl = filePath, }; // db.ImagesProduct.Add(ImageProductObject); // db.SaveChanges(); Product myProduct = db.Product.FirstOrDefault(p => p.ProductId == ProductId); myProduct.IamgesList.Add(ImageProductObject); db.SaveChanges(); } } } //return View(); return(RedirectToAction("Index")); }
public int AddImage(ImagesProduct item) { context.ImagesProducts.Add(item); return(context.SaveChanges()); }