Mercurial > altnet-hispano
comparison Agendas/trunk/src/Agendas.Web/Controllers/AgendaController.cs @ 10:c62b77fc33f4
website inicial
author | nelo@MTEySS.neluz.int |
---|---|
date | Sun, 13 Mar 2011 18:51:06 -0300 |
parents | |
children | 05996fa19e04 |
comparison
equal
deleted
inserted
replaced
9:c90492faf268 | 10:c62b77fc33f4 |
---|---|
1 using System; | |
2 using System.Collections.Generic; | |
3 using System.Linq; | |
4 using System.Web.Mvc; | |
5 using Agendas.Web.Models; | |
6 using AltNetHispano.Agendas.Domain; | |
7 using AltNetHispano.Agendas.Domain.Exceptions; | |
8 | |
9 namespace Agendas.Web.Controllers | |
10 { | |
11 public class AgendaController : Controller | |
12 { | |
13 public ActionResult Index() | |
14 { | |
15 var model = GetIndexModel(); | |
16 return View(model); | |
17 } | |
18 | |
19 private static AgendaIndexModel GetIndexModel() | |
20 { | |
21 var agenda = AgendaFactory.GetAgenda(); | |
22 | |
23 return new AgendaIndexModel | |
24 { | |
25 ProximosEventos = from e in agenda.GetEventosPublicados() | |
26 select new EventoDto {Id = e.Id.ToString(), Titulo = e.Titulo} | |
27 }; | |
28 } | |
29 | |
30 public ActionResult New() | |
31 { | |
32 return View(); | |
33 } | |
34 | |
35 [HttpPost] | |
36 public ActionResult New(AgendaNewModel model) | |
37 { | |
38 if (ModelState.IsValid) | |
39 { | |
40 var agenda = AgendaFactory.GetAgenda(); | |
41 | |
42 try | |
43 { | |
44 agenda.Publicar(new Van {Titulo = model.Titulo, Ponente = model.Ponente, Fecha = model.Fecha}); | |
45 | |
46 return View("Index", GetIndexModel()); | |
47 } | |
48 catch (ValidationException ex) | |
49 { | |
50 ModelState.AddModelError("error", ex.ToString()); | |
51 } | |
52 } | |
53 return View(model); | |
54 } | |
55 | |
56 | |
57 } | |
58 } |