diff Agendas/trunk/src/Agendas.Web/Controllers/EventoController.cs @ 25:e8d2be47a6b0

Cambios de nombre en Portal.Web (Agenda x Evento)
author nelo@MTEySS.neluz.int
date Tue, 15 Mar 2011 08:24:18 -0300
parents
children 71b02443450a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Web/Controllers/EventoController.cs	Tue Mar 15 08:24:18 2011 -0300
@@ -0,0 +1,99 @@
+using System;
+using System.Linq;
+using System.Web.Mvc;
+using Agendas.Factories;
+using Agendas.Web.Models;
+using AltNetHispano.Agendas.Domain.Exceptions;
+
+namespace Agendas.Web.Controllers
+{
+    public class EventoController : Controller
+    {
+        public ActionResult Index()
+        {
+            var model = GetIndexModel();
+            return View(model);
+        }
+
+        private static EventoIndexModel GetIndexModel()
+        {
+            var agenda = AgendaFactory.GetAgenda();
+
+            return new EventoIndexModel
+                       {
+                           ProximosEventos = from e in agenda.GetEventosPublicados()
+                                             select new EventoDto {Id = e.Id.ToString(), Titulo = e.Titulo}
+                       };
+        }
+
+		[Authorize]
+		public ActionResult New()
+        {
+            return View();
+        }
+
+        [HttpPost]
+		[Authorize]
+		public ActionResult New(EventoNewModel model)
+        {
+            if (ModelState.IsValid)
+            {
+                var agenda = AgendaFactory.GetAgenda();
+
+                try
+                {
+                    agenda.Publicar(model.Titulo, model.Ponente, model.Fecha);
+
+                    return View("Index", GetIndexModel());
+                }
+                catch (ValidationException ex)
+                {
+                    ModelState.AddModelError("error", ex.ToString());
+                }
+            }
+            return View(model);
+        }
+
+		[Authorize]
+		public ActionResult Edit(string id)
+		{
+			var agenda = AgendaFactory.GetAgenda();
+			var evento = agenda.GetEventoPublicado(new Guid(id));
+			if (evento!=null)
+			{
+				var model = new EventoEditModel
+				            	{
+				            		Id = id,
+				            		Titulo = evento.Titulo,
+				            		Ponente = evento.Ponente != null ? evento.Ponente.Nombre : string.Empty,
+				            		Fecha = evento.Fecha
+				            	};
+				return View(model);
+			}
+			ModelState.AddModelError("error","No se encontró el evento que quiere modificar");
+			return View();
+		}
+
+		[HttpPost]
+		[Authorize]
+		public ActionResult Edit(EventoEditModel model)
+		{
+			if (ModelState.IsValid)
+			{
+				var agenda = AgendaFactory.GetAgenda();
+
+				try
+				{
+					agenda.ModificarEvento(new Guid(model.Id), model.Titulo, model.Ponente, model.Fecha);
+
+					return View("Index", GetIndexModel());
+				}
+				catch (ValidationException ex)
+				{
+					ModelState.AddModelError("error", ex.ToString());
+				}
+			}
+			return View(model);
+		}
+    }
+}