Mercurial > altnet-hispano
view Agendas/trunk/src/Agendas.Web/Controllers/EventoController.cs @ 26:71b02443450a
UI de Propuestas de VANs
author | nelo@MTEySS.neluz.int |
---|---|
date | Tue, 15 Mar 2011 08:45:00 -0300 |
parents | e8d2be47a6b0 |
children | 29b8a8893ba3 |
line wrap: on
line source
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.GetEvento(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); } } }