diff Agendas/trunk/src/Agendas.Web/Controllers/PatrocinadorController.cs @ 275:bf993f99cee3

Ticket #123: Patrocinadores de las vans.
author juanjose.montesdeocaarbos
date Wed, 14 Dec 2011 08:15:44 -0300
parents
children 6f5ab71614d4
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Web/Controllers/PatrocinadorController.cs	Wed Dec 14 08:15:44 2011 -0300
@@ -0,0 +1,113 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Web;
+using System.Web.Mvc;
+using AltNetHispano.Agendas.Domain;
+using AltNetHispano.Agendas.Factories;
+using AltNetHispano.Agendas.Web.Models;
+using AltNetHispano.Agendas.Web.Services;
+
+
+namespace AltNetHispano.Agendas.Web.Controllers
+{
+    public class PatrocinadorController : Controller
+    {
+    	private IHttpServer _server;
+
+		public PatrocinadorController()
+		{
+			_server = (IHttpServer)ControllerContext.HttpContext.Server;
+		}
+
+		public PatrocinadorController(IHttpServer server)
+		{
+			_server = server;
+		}
+
+    	public ActionResult GetLogo(string id)
+		{
+			var patrocinadores = AgendaFactory.GetPatrocinadorRepository();
+
+			var patrocinador = patrocinadores.Get(new Guid(id));
+
+			return File(patrocinador.Logo, "image/jpg");
+		}
+
+    	public ActionResult Index()
+        {
+        	var patrocinadores = AgendaFactory.GetPatrocinadorRepository();
+
+        	var model = new PatrocinadorIndexModel
+        	            	{
+        	            		Items = from p in patrocinadores.GetAll()
+										select new PatrocinadorDto
+										       	{
+										       		Id = p.Id,
+													Nombre = p.Nombre
+										       	}
+        	            	};
+
+            return View(model);
+        }
+
+		[CustomAuthorize(Roles = Roles.Administrador)]
+        public ActionResult Nuevo()
+        {
+			var model = new PatrocinadorNewModel();
+			return View("DefaultEditor", model);
+        }
+
+        [HttpPost]
+		[CustomAuthorize(Roles = Roles.Administrador)]
+		public ActionResult Nuevo(PatrocinadorNewModel model)
+		{
+			if (ModelState.IsValid)
+			{
+				var tempLogoFile = Path.Combine(_server.MapPath("~/App_Data"), model.Nombre + model.Logo.FileName.Substring(model.Logo.FileName.LastIndexOf(".")));
+				model.Logo.SaveAs(tempLogoFile);
+
+				var patrocinadores = AgendaFactory.GetPatrocinadorRepository();
+
+				var patrocinador = new Patrocinador(model.Nombre);
+				patrocinador.LoadLogo(tempLogoFile);
+				
+				patrocinadores.Save(patrocinador);
+
+				return RedirectToAction("Index");
+			}
+
+			return View("DefaultEditor", model);
+        }
+
+    	[CustomAuthorize(Roles = Roles.Administrador)]
+		public ActionResult Modificar(int id)
+        {
+            return View();
+        }
+
+        [HttpPost]
+		[CustomAuthorize(Roles = Roles.Administrador)]
+		public ActionResult Modificar(int id, FormCollection collection)
+        {
+            try
+            {
+                // TODO: Add update logic here
+ 
+                return RedirectToAction("Index");
+            }
+            catch
+            {
+                return View();
+            }
+        }
+
+		[CustomAuthorize(Roles = Roles.Administrador)]
+		public ActionResult Quitar(int id)
+        {
+            return View();
+        }
+
+    }
+}