comparison Agendas/trunk/src/Agendas.Web/Controllers/EventoController.cs @ 25:e8d2be47a6b0

Cambios de nombre en Portal.Web (Agenda x Evento)
author nelo@MTEySS.neluz.int
date Tue, 15 Mar 2011 08:24:18 -0300
parents
children 71b02443450a
comparison
equal deleted inserted replaced
24:41b283d27e3e 25:e8d2be47a6b0
1 using System;
2 using System.Linq;
3 using System.Web.Mvc;
4 using Agendas.Factories;
5 using Agendas.Web.Models;
6 using AltNetHispano.Agendas.Domain.Exceptions;
7
8 namespace Agendas.Web.Controllers
9 {
10 public class EventoController : Controller
11 {
12 public ActionResult Index()
13 {
14 var model = GetIndexModel();
15 return View(model);
16 }
17
18 private static EventoIndexModel GetIndexModel()
19 {
20 var agenda = AgendaFactory.GetAgenda();
21
22 return new EventoIndexModel
23 {
24 ProximosEventos = from e in agenda.GetEventosPublicados()
25 select new EventoDto {Id = e.Id.ToString(), Titulo = e.Titulo}
26 };
27 }
28
29 [Authorize]
30 public ActionResult New()
31 {
32 return View();
33 }
34
35 [HttpPost]
36 [Authorize]
37 public ActionResult New(EventoNewModel model)
38 {
39 if (ModelState.IsValid)
40 {
41 var agenda = AgendaFactory.GetAgenda();
42
43 try
44 {
45 agenda.Publicar(model.Titulo, model.Ponente, model.Fecha);
46
47 return View("Index", GetIndexModel());
48 }
49 catch (ValidationException ex)
50 {
51 ModelState.AddModelError("error", ex.ToString());
52 }
53 }
54 return View(model);
55 }
56
57 [Authorize]
58 public ActionResult Edit(string id)
59 {
60 var agenda = AgendaFactory.GetAgenda();
61 var evento = agenda.GetEventoPublicado(new Guid(id));
62 if (evento!=null)
63 {
64 var model = new EventoEditModel
65 {
66 Id = id,
67 Titulo = evento.Titulo,
68 Ponente = evento.Ponente != null ? evento.Ponente.Nombre : string.Empty,
69 Fecha = evento.Fecha
70 };
71 return View(model);
72 }
73 ModelState.AddModelError("error","No se encontró el evento que quiere modificar");
74 return View();
75 }
76
77 [HttpPost]
78 [Authorize]
79 public ActionResult Edit(EventoEditModel model)
80 {
81 if (ModelState.IsValid)
82 {
83 var agenda = AgendaFactory.GetAgenda();
84
85 try
86 {
87 agenda.ModificarEvento(new Guid(model.Id), model.Titulo, model.Ponente, model.Fecha);
88
89 return View("Index", GetIndexModel());
90 }
91 catch (ValidationException ex)
92 {
93 ModelState.AddModelError("error", ex.ToString());
94 }
95 }
96 return View(model);
97 }
98 }
99 }