comparison Agendas/trunk/src/Agendas.Web/Controllers/EventoController.cs @ 185:2d02adb79322

Se agrega fecha de termino de un Evento y se incluye la hora a la fecha de inicio. Se modifica la propiedad Fecha del Evento, renombrandola FechaInicio. En el ModelView se agrega propiedades DuraciĆ³n y Hora del Evento cuando es Modificado, Nuevo y Agendado. Las fechas ingresadas son creadas en sistema UTC Queda pendiente Agregar duraciĆ³n a Google Calendar.
author alabra
date Tue, 09 Aug 2011 01:04:27 -0400
parents 212c664db5aa
children 607384590bf8
comparison
equal deleted inserted replaced
184:2a336a6a76b5 185:2d02adb79322
11 { 11 {
12 public ActionResult Index() 12 public ActionResult Index()
13 { 13 {
14 var agenda = AgendaFactory.GetAgenda(); 14 var agenda = AgendaFactory.GetAgenda();
15 15
16 var model = new EventoIndexModel 16 var model = new EventoIndexModel
17 { 17 {
18 ProximosEventos = from e in agenda.GetEventosActivos() 18 ProximosEventos = from e in agenda.GetEventosActivos()
19 orderby e.Fecha 19 orderby e.FechaInicio
20 select new EventoDto 20 select new EventoDto
21 { 21 {
22 Id = e.Id.ToString(), 22 Id = e.Id.ToString(),
23 Titulo = e.Titulo, 23 Titulo = e.Titulo,
24 Fecha = e.Fecha.HasValue ? e.Fecha.Value.ToShortDateString() : string.Empty, 24 Fecha =
25 Estado = e.Estado.Descripcion, 25 e.FechaInicio.HasValue
26 PuedeAgendar = e.Estado.PuedePromover(Accion.Agendar), 26 ? e.FechaInicio.Value.ToShortDateString() + " " +
27 PuedeModificar = e.Estado.PuedePromover(Accion.Modificar), 27 e.FechaInicio.Value.ToShortTimeString()
28 PuedeConfirmar = e.Estado.PuedePromover(Accion.Confirmar), 28 : string.Empty,
29 PuedePublicar = e.Estado.PuedePromover(Accion.Publicar), 29 Duracion =
30 PuedeCancelar = e.Estado.PuedePromover(Accion.Cancelar), 30 e.FechaInicio.HasValue && e.FechaTermino.HasValue
31 PuedeDescartar = e.Estado.PuedePromover(Accion.Descartar), 31 ? e.FechaTermino.Value.Subtract(e.FechaInicio.Value).
32 PuedeReAgendar = e.Estado.PuedePromover(Accion.ReAgendar), 32 ToString("c")
33 PuedeReProponer = e.Estado.PuedePromover(Accion.ReProponer) 33 : string.Empty,
34 } 34 Estado = e.Estado.Descripcion,
35 }; 35 PuedeAgendar = e.Estado.PuedePromover(Accion.Agendar),
36 PuedeModificar = e.Estado.PuedePromover(Accion.Modificar),
37 PuedeConfirmar = e.Estado.PuedePromover(Accion.Confirmar),
38 PuedePublicar = e.Estado.PuedePromover(Accion.Publicar),
39 PuedeCancelar = e.Estado.PuedePromover(Accion.Cancelar),
40 PuedeDescartar = e.Estado.PuedePromover(Accion.Descartar),
41 PuedeReAgendar = e.Estado.PuedePromover(Accion.ReAgendar),
42 PuedeReProponer = e.Estado.PuedePromover(Accion.ReProponer)
43 }
44 };
36 return View(model); 45 return View(model);
37 } 46 }
38 47
39 [CustomAuthorize(Roles = Roles.Administrador)] 48 [CustomAuthorize(Roles = Roles.Administrador)]
40 public ActionResult Nuevo() 49 public ActionResult Nuevo()
41 { 50 {
42 var model = new EventoNewModel {Fecha = DateTime.Now}; 51 var model = new EventoNewModel { Fecha = DateTime.Now, Duracion = new TimeSpan(2, 0, 0), Hora = new TimeSpan(18, 0, 0) };
43 return View("Defaulteditor", model); 52 return View("Defaulteditor", model);
44 } 53 }
45 54
46 [HttpPost] 55 [HttpPost]
47 [CustomAuthorize(Roles = Roles.Administrador)] 56 [CustomAuthorize(Roles = Roles.Administrador)]
48 public ActionResult Nuevo(EventoNewModel model) 57 public ActionResult Nuevo(EventoNewModel model)
49 { 58 {
50 return 59 return
51 GenericAction( 60 GenericAction(
52 (agenda, m) => agenda.Agendar(m.Titulo, m.Ponente, m.Fecha, m.UrlInvitacion, (TipoEvento) m.TipoEvento), 61 (agenda, m) => agenda.Agendar(m.Titulo, m.Ponente, GenerarFechaInicio(m.Fecha, m.Hora),
53 m => View("Defaulteditor", m), 62 GenerarFechaTermino(m.Fecha, m.Hora, m.Duracion), m.UrlInvitacion,
54 model); 63 (TipoEvento) m.TipoEvento),
64 m => View("Defaulteditor", m),
65 model);
55 } 66 }
56 67
57 [CustomAuthorize(Roles = Roles.Administrador)] 68 [CustomAuthorize(Roles = Roles.Administrador)]
58 public ActionResult Confirmar(string id) 69 public ActionResult Confirmar(string id)
59 { 70 {
101 var model = new EventoEditModel 112 var model = new EventoEditModel
102 { 113 {
103 Id = id, 114 Id = id,
104 Titulo = evento.Titulo, 115 Titulo = evento.Titulo,
105 Ponente = evento.Ponente != null ? evento.Ponente.Id : Guid.Empty, 116 Ponente = evento.Ponente != null ? evento.Ponente.Id : Guid.Empty,
106 Fecha = evento.Fecha, 117 Fecha = evento.FechaInicio,
118 Hora = evento.FechaInicio != null ? evento.FechaInicio.Value.TimeOfDay : (TimeSpan?)null,
119 Duracion = evento.FechaInicio!=null && evento.FechaTermino!=null ? evento.FechaTermino.Value.Subtract(evento.FechaInicio.Value) : (TimeSpan?) null,
107 UrlInvitacion = evento.UrlInvitacion 120 UrlInvitacion = evento.UrlInvitacion
108 }; 121 };
109 return View("Defaulteditor", model); 122 return View("Defaulteditor", model);
110 } 123 }
111 124
112 [HttpPost] 125 [HttpPost]
113 [CustomAuthorize(Roles = Roles.Administrador)] 126 [CustomAuthorize(Roles = Roles.Administrador)]
114 public ActionResult Modificar(EventoEditModel model) 127 public ActionResult Modificar(EventoEditModel model)
115 { 128 {
116 return 129 return
117 GenericAction( 130 GenericAction(
118 (agenda, m) => agenda.ModificarEvento(new Guid(m.Id), m.Titulo, m.Ponente, m.Fecha.Value, m.UrlInvitacion), 131 (agenda, m) =>
119 m => View("Defaulteditor", m), 132 agenda.ModificarEvento(new Guid(m.Id), m.Titulo, m.Ponente, GenerarFechaInicio(m.Fecha, m.Hora),
120 model); 133 GenerarFechaTermino(m.Fecha, m.Hora, m.Duracion), m.UrlInvitacion),
134 m => View("Defaulteditor", m),
135 model);
121 } 136 }
122 137
123 [CustomAuthorize(Roles = Roles.Administrador)] 138 [CustomAuthorize(Roles = Roles.Administrador)]
124 public ActionResult Agendar(string id) 139 public ActionResult Agendar(string id)
125 { 140 {
129 var model = new EventoAgendarModel 144 var model = new EventoAgendarModel
130 { 145 {
131 Id = id, 146 Id = id,
132 Titulo = evento.Titulo, 147 Titulo = evento.Titulo,
133 Ponente = evento.Ponente != null ? evento.Ponente.Id : Guid.Empty, 148 Ponente = evento.Ponente != null ? evento.Ponente.Id : Guid.Empty,
134 Fecha = evento.Fecha, 149 Fecha = evento.FechaInicio,
150 Hora = evento.FechaInicio != null ? evento.FechaInicio.Value.TimeOfDay : (TimeSpan?)null,
151 Duracion = evento.FechaInicio != null && evento.FechaTermino != null ? evento.FechaTermino.Value.Subtract(evento.FechaInicio.Value) : (TimeSpan?)null,
135 UrlInvitacion = evento.UrlInvitacion 152 UrlInvitacion = evento.UrlInvitacion
136 }; 153 };
137 return View("Defaulteditor", model); 154 return View("Defaulteditor", model);
138 } 155 }
139 156
140 [HttpPost] 157 [HttpPost]
141 [CustomAuthorize(Roles = Roles.Administrador)] 158 [CustomAuthorize(Roles = Roles.Administrador)]
142 public ActionResult Agendar(EventoAgendarModel model) 159 public ActionResult Agendar(EventoAgendarModel model)
143 { 160 {
144 return 161 return
145 GenericAction( 162 GenericAction(
146 (agenda, m) => agenda.ModificarEvento(new Guid(m.Id), m.Titulo, m.Ponente, m.Fecha.Value, m.UrlInvitacion), 163 (agenda, m) =>
147 m => View("Defaulteditor", m), 164 agenda.ModificarEvento(new Guid(m.Id), m.Titulo, m.Ponente, GenerarFechaInicio(m.Fecha, m.Hora),
148 model); 165 GenerarFechaTermino(m.Fecha, m.Hora, m.Duracion), m.UrlInvitacion),
166 m => View("Defaulteditor", m),
167 model);
149 } 168 }
150 169
151 [CustomAuthorize(Roles = Roles.Administrador)] 170 [CustomAuthorize(Roles = Roles.Administrador)]
152 public ActionResult Proponer() 171 public ActionResult Proponer()
153 { 172 {
223 ModelState.AddModelError("error", r.ToString()); 242 ModelState.AddModelError("error", r.ToString());
224 } 243 }
225 return actionresultOnFail.Invoke(model); 244 return actionresultOnFail.Invoke(model);
226 } 245 }
227 246
247 private DateTime? GenerarFechaInicio(DateTime? fecha, TimeSpan? hora)
248 {
249 return fecha.HasValue && hora.HasValue
250 ? new DateTime(fecha.Value.Year, fecha.Value.Month, fecha.Value.Day, hora.Value.Hours,
251 hora.Value.Minutes, hora.Value.Seconds, DateTimeKind.Utc)
252 : (DateTime?) null;
253 }
254 private DateTime? GenerarFechaTermino(DateTime? fecha, TimeSpan? hora, TimeSpan? duracion)
255 {
256 return fecha.HasValue && hora.HasValue && duracion.HasValue
257 ? new DateTime(fecha.Value.Year, fecha.Value.Month, fecha.Value.Day, hora.Value.Hours,
258 hora.Value.Minutes, hora.Value.Seconds, DateTimeKind.Utc).Add(duracion.Value)
259 : (DateTime?) null;
260 }
228 261
229 } 262 }
230 } 263 }