private static int InsertUpdate(TBImage objTImagen, bool isUpdate, string storedProcName) { int newlyCreatedIntImagen = objTImagen.intImagen; SqlCommand command = new SqlCommand(); command.CommandText = "TImagen_Update"; command.CommandType = CommandType.StoredProcedure; SqlConnection staticConnection = StaticSqlConnection; command.Connection = staticConnection; try { staticConnection.Open(); // parameters //if (isUpdate) //{ // // for update only // command.Parameters.AddWithValue("@intImagen", objTImagen.intImagen); //} command.Parameters.AddWithValue("@vchNombre", objTImagen.vchNombre); command.Parameters.AddWithValue("@vchExtencion", objTImagen.vchExtencion); command.Parameters.AddWithValue("@vchImagen", objTImagen.vchImagen); command.Parameters.AddWithValue("@intPremio", objTImagen.intPremio); if (isUpdate) { command.ExecuteNonQuery(); } } catch (Exception ex) { throw; } finally { staticConnection.Close(); command.Dispose(); } return(newlyCreatedIntImagen); }
public ActionResult UploadImg() { if (Request.Files.Count > 0) { //try //{ HttpFileCollectionBase files = Request.Files; HttpPostedFileBase archivo = files[0]; if (archivo == null || archivo.ContentLength == 0) { return(Json("Seleccione una Imagen.")); } else { if (archivo.FileName.EndsWith("jpg") || archivo.FileName.EndsWith("jpeg") || archivo.FileName.EndsWith("png")) { byte[] byteImg = null; using (BinaryReader br = new BinaryReader(archivo.InputStream)) { byteImg = br.ReadBytes(archivo.ContentLength); br.BaseStream.Read(byteImg, 0, archivo.ContentLength); } string intPremio = Request.Form["intPremio"].ToString(); Int32 SelectedCampañaId = Convert.ToInt32(Request.Form["intCampana"]); TBImage objImage = new TBImage(); objImage.vchNombre = archivo.FileName.ToString(); objImage.vchImagen = byteImg; objImage.intPremio = Convert.ToInt32(intPremio); objImage.vchExtencion = Path.GetExtension(archivo.FileName); DAOImage.Update(objImage); } ; } } TBPremioModel obj = CargaDatosInicial(); return(View("Index", obj)); }
public static void Update(TBImage objTImagen) { string storedProcName = "TImagen_Update"; InsertUpdate(objTImagen, true, storedProcName); }