Mercurial > altnet-hispano
view Agendas/trunk/src/Agendas.Web/Controllers/AgendaController.cs @ 19:74eb4577d447
HttpContext identity provider
Requerimiento de autenticación para registrar un nuevo evento o modificar uno existente
author | nelo@MTEySS.neluz.int |
---|---|
date | Mon, 14 Mar 2011 00:35:43 -0300 |
parents | 08b9e96132a5 |
children | 41b283d27e3e |
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 AgendaController : Controller { public ActionResult Index() { var model = GetIndexModel(); return View(model); } private static AgendaIndexModel GetIndexModel() { var agenda = AgendaFactory.GetAgenda(); return new AgendaIndexModel { 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(AgendaNewModel 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 AgendaEditModel {Id = id, Titulo = evento.Titulo, Ponente = evento.Ponente, Fecha = evento.Fecha}; return View(model); } ModelState.AddModelError("error","No se encontró el evento que quiere modificar"); return View(); } [HttpPost] [Authorize] public ActionResult Edit(AgendaEditModel 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); } } }