# HG changeset patch # User nelopauselli # Date 1329579234 10800 # Node ID 8c742d5ccf67518b37cf2279ab99f25c7fa48cf3 # Parent 0e616662a94b539c5a3d6ea582fdc60222669f4e Leyendo imagen directamente desde el stream diff -r 0e616662a94b -r 8c742d5ccf67 Agendas/trunk/src/Agendas.Web/Controllers/PatrocinadorController.cs --- a/Agendas/trunk/src/Agendas.Web/Controllers/PatrocinadorController.cs Fri Feb 17 14:28:05 2012 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Controllers/PatrocinadorController.cs Sat Feb 18 12:33:54 2012 -0300 @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.IO; using System.Linq; using System.Web; @@ -82,12 +83,9 @@ if (patrocinadores.GetByNombre(model.Nombre) == null) { - var tempLogoFile = Path.Combine(HttpServer.MapPath("~/App_Data"), - model.Nombre + - model.Logo.FileName.Substring(model.Logo.FileName.LastIndexOf("."))); - model.Logo.SaveAs(tempLogoFile); var patrocinador = new Patrocinador(model.Nombre); - patrocinador.LoadLogo(tempLogoFile); + + patrocinador.Logo = StreamToArray(model.Logo.InputStream); patrocinadores.Save(patrocinador); @@ -99,7 +97,19 @@ return View("DefaultEditor", model); } - [CustomAuthorize(Roles = Roles.Administrador)] + private static byte[] StreamToArray(Stream stream) + { + var buffer = new byte[16*1024]; + using (var ms = new MemoryStream()) + { + int read; + while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) + ms.Write(buffer, 0, read); + return ms.ToArray(); + } + } + + [CustomAuthorize(Roles = Roles.Administrador)] public ActionResult Modificar(string id) { var patrocinadores = AgendaFactory.GetPatrocinadorRepository();