10
|
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 }
|