private List<ImagenProducto> ObtenerImagenesProducto(long ProductoID, string item) { List<ImagenProducto> lista = new List<ImagenProducto>(); var json = ripJson("/items/" + item); foreach (var picture in json.pictures) { var webCli = new WebClient(); byte[] bytes = webCli.DownloadData((string)picture.url); ImagenProducto im = new ImagenProducto { ProductoID=ProductoID, Imagen = bytes}; lista.Add(im); } return lista; }
public void UploadFile() { if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any()) { // Obtener la imagen subida var httpPostedFile = System.Web.HttpContext.Current.Request.Files["UploadedImage"]; String usuarioId = User.Identity.Name; String tienda = Session["Tienda_Nombre"].ToString(); long prodId = Convert.ToInt64(System.Web.HttpContext.Current.Request.Form["ProductoID"]); if (httpPostedFile != null) { byte[] imageBytes = null; using (var binaryReader = new BinaryReader(httpPostedFile.InputStream)) { imageBytes = binaryReader.ReadBytes(httpPostedFile.ContentLength); } ImagenProducto ip = new ImagenProducto { ProductoID = prodId, Imagen = imageBytes }; cS.AgregarImagenProducto(ip, tienda); } } }
//--IMAGENES-- public void AgregarImagenProducto(ImagenProducto ip, string idTienda) { try { chequearTienda(idTienda); using (var context = ChebayDBContext.CreateTenant(idTienda)) { context.imagenesproducto.Add(ip); context.SaveChanges(); } } catch (Exception e) { Debug.WriteLine(e.Message); throw e; } }