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