changeset 295:8c742d5ccf67

Leyendo imagen directamente desde el stream
author nelopauselli
date Sat, 18 Feb 2012 12:33:54 -0300
parents 0e616662a94b
children 1edd42d24711
files Agendas/trunk/src/Agendas.Web/Controllers/PatrocinadorController.cs
diffstat 1 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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();