annotate Agendas/trunk/src/Agendas.Web/Controllers/AgendaController.cs @ 15:08b9e96132a5

Persistimos los eventos de la agenda
author nelo@MTEySS.neluz.int
date Mon, 14 Mar 2011 00:14:09 -0300
parents ed6d842abf42
children 74eb4577d447
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;
15
08b9e96132a5 Persistimos los eventos de la agenda
nelo@MTEySS.neluz.int
parents: 14
diff changeset
5 using Agendas.Factories;
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
6 using Agendas.Web.Models;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
7 using AltNetHispano.Agendas.Domain;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
8 using AltNetHispano.Agendas.Domain.Exceptions;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
9
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
10 namespace Agendas.Web.Controllers
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
11 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
12 public class AgendaController : Controller
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
13 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
14 public ActionResult Index()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
15 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
16 var model = GetIndexModel();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
17 return View(model);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
18 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
19
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
20 private static AgendaIndexModel GetIndexModel()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
21 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
22 var agenda = AgendaFactory.GetAgenda();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
23
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
24 return new AgendaIndexModel
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
25 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
26 ProximosEventos = from e in agenda.GetEventosPublicados()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
27 select new EventoDto {Id = e.Id.ToString(), Titulo = e.Titulo}
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
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
31 public ActionResult New()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
32 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
33 return View();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
34 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
35
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
36 [HttpPost]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
37 public ActionResult New(AgendaNewModel model)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
38 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
39 if (ModelState.IsValid)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
40 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
41 var agenda = AgendaFactory.GetAgenda();
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
42
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
43 try
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
44 {
12
05996fa19e04 Unificamos Van y Cafe en Evento
nelo@MTEySS.neluz.int
parents: 10
diff changeset
45 agenda.Publicar(model.Titulo, model.Ponente, model.Fecha);
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
46
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
47 return View("Index", GetIndexModel());
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
48 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
49 catch (ValidationException ex)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
50 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
51 ModelState.AddModelError("error", ex.ToString());
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
52 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
53 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
54 return View(model);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
55 }
14
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
56
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
57 public ActionResult Edit(string id)
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
58 {
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
59 var agenda = AgendaFactory.GetAgenda();
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
60 var evento = agenda.GetEventoPublicado(new Guid(id));
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
61 if (evento!=null)
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
62 {
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
63 var model = new AgendaEditModel {Id = id, Titulo = evento.Titulo, Ponente = evento.Ponente, Fecha = evento.Fecha};
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
64 return View(model);
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
65 }
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
66 ModelState.AddModelError("error","No se encontró el evento que quiere modificar");
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
67 return View();
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
68 }
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
69
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
70 [HttpPost]
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
71 public ActionResult Edit(AgendaEditModel model)
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
72 {
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
73 if (ModelState.IsValid)
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
74 {
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
75 var agenda = AgendaFactory.GetAgenda();
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
76
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
77 try
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
78 {
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
79 agenda.ModificarEvento(new Guid(model.Id), model.Titulo, model.Ponente, model.Fecha);
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
80
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
81 return View("Index", GetIndexModel());
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
82 }
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
83 catch (ValidationException ex)
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
84 {
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
85 ModelState.AddModelError("error", ex.ToString());
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
86 }
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
87 }
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
88 return View(model);
ed6d842abf42 Modificar evento
nelo@MTEySS.neluz.int
parents: 12
diff changeset
89 }
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
90 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
91 }