public void AltaFotoLugar(FotosLugar F, Lugar L) { MySqlConnection con = new MySqlConnection(Conexion.Cnn); MySqlCommand comando = new MySqlCommand("AltaFotosLugar", con); comando.CommandType = CommandType.StoredProcedure; comando.Parameters.AddWithValue("pNombreFoto", F.NombreFoto); comando.Parameters.AddWithValue("pFoto", F.Imagen); comando.Parameters.AddWithValue("pNombreLugar", L.Nombre); comando.Parameters.AddWithValue("pExtension", F.Extension); try { con.Open(); comando.ExecuteNonQuery(); } catch (Exception ex) { throw new ApplicationException("Problema con la base de datos: " + ex.Message); } finally { con.Close(); } }
public void AgregarFotosLugar(Lugar L) { MySqlConnection conexion = new MySqlConnection(Conexion.Cnn); MySqlCommand comando = new MySqlCommand("ListarFotosLugar", conexion); comando.CommandType = CommandType.StoredProcedure; comando.Parameters.AddWithValue("pNombreLugar", L.Nombre); try { conexion.Open(); MySqlDataReader lector = comando.ExecuteReader(); if (lector.HasRows) { while (lector.Read()) { FotosLugar foto = new FotosLugar((string)lector["NombreFoto"], (byte[])lector["Foto"], (string)lector["Extension"]); L.AgregarFoto(foto); } } } catch (Exception ex) { throw new ApplicationException("Problema con la base de datos: " + ex.Message); } finally { conexion.Close(); } }
public ActionResult AgregarFoto(HttpPostedFileBase image1) { List <EntidadesCompartidas.FotosLugar> list = null; list = (List <EntidadesCompartidas.FotosLugar>)Session["Fotos"]; EntidadesCompartidas.FotosLugar foto = new FotosLugar(); if (image1 != null) { foto.Extension = Path.GetExtension(image1.FileName); int length = image1.ContentLength; byte[] buffer = new byte[length]; image1.InputStream.Read(buffer, 0, length); foto.Imagen = buffer; foto.NombreFoto = image1.FileName.Substring(0, image1.FileName.LastIndexOf('.')); } if (list == null) { list = new List <FotosLugar>(); list.Add(foto); } else { list.Add(foto); } string JsonFotos = JsonConvert.SerializeObject(list); Session["FotosJson"] = JsonFotos; Session["Fotos"] = list; return(View("AdministrarLugares")); }