view Agendas/trunk/src/Agendas.Web/Controllers/EventoController.cs @ 182:beeb48ddb44a

Warning con los errores que se guarden en el log del track de un evento durante una notificación (twitter, calendar, blog)
author nelopauselli
date Mon, 08 Aug 2011 21:57:10 -0300
parents 1deccd6c3cb2
children 212c664db5aa
line wrap: on
line source

using System;
using System.Linq;
using System.Web.Mvc;
using AltNetHispano.Agendas.Domain;
using AltNetHispano.Agendas.Factories;
using AltNetHispano.Agendas.Web.Models;

namespace AltNetHispano.Agendas.Web.Controllers
{
    public class EventoController : Controller
	{
		public ActionResult Index()
		{
			var agenda = AgendaFactory.GetAgenda();

			var model = new EventoIndexModel
			            	{
			            		ProximosEventos = from e in agenda.GetEventosActivos()
			            		                  orderby e.Fecha
			            		                  select new EventoDto
			            		                         	{
			            		                         		Id = e.Id.ToString(),
			            		                         		Titulo = e.Titulo,
			            		                         		Fecha = e.Fecha.HasValue ? e.Fecha.Value.ToShortDateString() : string.Empty,
																Estado = e.Estado.Descripcion,
			            		                         		PuedeAgendar = e.Estado.PuedePromover(Accion.Agendar),
			            		                         		PuedeModificar = e.Estado.PuedePromover(Accion.Modificar),
			            		                         		PuedeConfirmar = e.Estado.PuedePromover(Accion.Confirmar),
			            		                         		PuedePublicar = e.Estado.PuedePromover(Accion.Publicar),
                                                                PuedeCancelar = e.Estado.PuedePromover(Accion.Cancelar),
                                                                PuedeDescartar = e.Estado.PuedePromover(Accion.Descartar),
                                                                PuedeReAgendar = e.Estado.PuedePromover(Accion.ReAgendar),
                                                                PuedeReProponer = e.Estado.PuedePromover(Accion.ReProponer)
			            		                         	}
			            	};
			return View(model);
		}

		[CustomAuthorize(Roles = Roles.Administrador)]
		public ActionResult Nuevo()
		{
		    var model = new EventoNewModel {Fecha = DateTime.Now};
		    return View("Defaulteditor", model);
		}

		[HttpPost]
		[CustomAuthorize(Roles = Roles.Administrador)]
		public ActionResult Nuevo(EventoNewModel model)
		{
			if (ModelState.IsValid)
			{
				var agenda = AgendaFactory.GetAgenda();

				var r = agenda.Agendar(model.Titulo, model.Ponente, model.Fecha,
				  model.UrlInvitacion, (TipoEvento)model.TipoEvento);
				if (r.Succeful)
				{
					this.AddNotification("Evento creado");
					foreach (var log in r.Warnings)
						this.AddWarning(log.WarningMessage);
					return RedirectToAction("Index");
				}
				ModelState.AddModelError("error", r.ToString());
			}
            return View("Defaulteditor", model);
		}

		[CustomAuthorize(Roles = Roles.Administrador)]
		public ActionResult Confirmar(string id)
		{
			var agenda = AgendaFactory.GetAgenda();
			
			var r = agenda.Confirmar(new Guid(id));
			if (r.Succeful)
			{
				this.AddNotification("Evento confirmado");
				foreach (var log in r.Warnings)
					this.AddWarning(log.WarningMessage);
			}
			else
				this.AddError("Evento confirmado");

			return RedirectToAction("Index");
		}

		[CustomAuthorize(Roles = Roles.Administrador)]
		public ActionResult Publicar(string id)
		{
			var agenda = AgendaFactory.GetAgenda();
			var evento = agenda.GetEvento(new Guid(id));

			var model = new EventoPublicarModel
			{
				Id = id,
				Titulo = evento.Titulo,
				NroOrden = 0, //TODO: Obtener el último y sumarle uno.
				UrlWiki = evento.UrlWiki,
				DuracionReal = new TimeSpan(0, 0, 0)
			};
			return View("Defaulteditor", model);
		}

		[HttpPost]
		[CustomAuthorize(Roles = Roles.Administrador)]
		public ActionResult Publicar(EventoPublicarModel model)
		{
			if (ModelState.IsValid)
			{
				var agenda = AgendaFactory.GetAgenda();

				var r = agenda.Publicar(new Guid(model.Id), model.NroOrden, model.UrlWiki, model.DuracionReal);
				if (r.Succeful)
				{
					this.AddNotification(string.Format("Evento publicado {0}", model.Titulo));
					foreach (var log in r.Warnings)
						this.AddWarning(log.WarningMessage);
					return RedirectToAction("Index");
				}
				ModelState.AddModelError("error", r.ToString());
			}
			return View("Defaulteditor", model);
		}

		[CustomAuthorize(Roles = Roles.Administrador)]
		public ActionResult Modificar(string id)
		{
			var agenda = AgendaFactory.GetAgenda();
			var evento = agenda.GetEvento(new Guid(id));

			var model = new EventoEditModel
			{
				Id = id,
				Titulo = evento.Titulo,
				Ponente = evento.Ponente != null ? evento.Ponente.Id : Guid.Empty,
				Fecha = evento.Fecha,
				UrlInvitacion = evento.UrlInvitacion
			};
            return View("Defaulteditor", model);
		}
		
		[HttpPost]
		[CustomAuthorize(Roles = Roles.Administrador)]
		public ActionResult Modificar(EventoEditModel model)
		{
			if (ModelState.IsValid)
			{
				var agenda = AgendaFactory.GetAgenda();

				var r = agenda.ModificarEvento(new Guid(model.Id), model.Titulo, model.Ponente, model.Fecha.Value, model.UrlInvitacion);
				if (r.Succeful)
				{
					this.AddNotification("evento modificado");
					foreach (var log in r.Warnings)
						this.AddWarning(log.WarningMessage);
					return RedirectToAction("Index");
				}
				ModelState.AddModelError("error", r.ToString());
			}
            return View("Defaulteditor", model);
		}

		[CustomAuthorize(Roles = Roles.Administrador)]
		public ActionResult Agendar(string id)
		{
			var agenda = AgendaFactory.GetAgenda();
			var evento = agenda.GetEvento(new Guid(id));

			var model = new EventoAgendarModel
			{
				Id = id,
				Titulo = evento.Titulo,
				Ponente = evento.Ponente != null ? evento.Ponente.Id : Guid.Empty,
				Fecha = evento.Fecha,
				UrlInvitacion = evento.UrlInvitacion
			};
            return View("Defaulteditor", model);
		}

		[HttpPost]
		[CustomAuthorize(Roles = Roles.Administrador)]
		public ActionResult Agendar(EventoAgendarModel model)
		{
			if (ModelState.IsValid)
			{
				var agenda = AgendaFactory.GetAgenda();

				var r = agenda.ModificarEvento(new Guid(model.Id), model.Titulo, model.Ponente, model.Fecha.Value, model.UrlInvitacion);
				if (r.Succeful)
				{
					this.AddNotification("evento agendado");
					foreach (var log in r.Warnings)
						this.AddWarning(log.WarningMessage);
					return RedirectToAction("Index");
				}
				ModelState.AddModelError("error", r.ToString());
			}
            return View("Defaulteditor", model);
		}

		[CustomAuthorize(Roles = Roles.Administrador)]
		public ActionResult Proponer()
		{
			throw new NotImplementedException();
			var model = new PropuestaNewModel();
            return View("Defaulteditor", model);
		}

		[HttpPost]
		[CustomAuthorize(Roles = Roles.Administrador)]
		public ActionResult Proponer(PropuestaNewModel model)
		{
			throw new NotImplementedException();
			if (ModelState.IsValid)
			{
				var agenda = AgendaFactory.GetAgenda();

				var r = agenda.Proponer(model.Titulo, model.Ponente, model.UrlInvitacion, (TipoEvento)model.TipoEvento);
				if (r.Succeful)
				{
					this.AddNotification("Evento propuesto");
					foreach (var log in r.Warnings)
						this.AddWarning(log.WarningMessage);
					return RedirectToAction("Index");
				}
				ModelState.AddModelError("error", r.ToString());
			}
            return View("Defaulteditor", model);
		}

		[CustomAuthorize(Roles = Roles.Administrador)]
	    public ActionResult Cancelar(string id)
	    {
            var agenda = AgendaFactory.GetAgenda();
            var r = agenda.Cancelar(new Guid(id));

			if (r.Succeful)
			{
				this.AddNotification("Evento cancelado");
				foreach (var log in r.Warnings)
					this.AddWarning(log.WarningMessage);
			}
			else
			this.AddError(r.Message);
			return RedirectToAction("Index");
	    }

		[CustomAuthorize(Roles = Roles.Administrador)]
	    public ActionResult Descartar(string id)
	    {
            var agenda = AgendaFactory.GetAgenda();
            var r = agenda.Descartar(new Guid(id));

			if (r.Succeful)
            {this.AddNotification("Evento descartado");
			foreach (var log in r.Warnings)
				this.AddWarning(log.WarningMessage);
			}
			else
				this.AddError(r.Message);
            return RedirectToAction("Index");
	    }

		[CustomAuthorize(Roles = Roles.Administrador)]
	    public ActionResult ReAgendar(string id)
	    {
            var agenda = AgendaFactory.GetAgenda();
            var r = agenda.ReAgendar(new Guid(id));

			if (r.Succeful)
            {this.AddNotification("Evento re-agendado");
			foreach (var log in r.Warnings)
				this.AddWarning(log.WarningMessage);
			}
			else
				this.AddError(r.Message);

            return RedirectToAction("Index");
	    }

		[CustomAuthorize(Roles = Roles.Administrador)]
	    public ActionResult ReProponer(string id)
	    {
            var agenda = AgendaFactory.GetAgenda();
            var r = agenda.ReProponer(new Guid(id));

			if (r.Succeful)
			{
				this.AddNotification("Evento re-propuesto");
				foreach (var log in r.Warnings)
					this.AddWarning(log.WarningMessage);
			}
			else
				this.AddError(r.Message);
            return RedirectToAction("Index");
	    }
	}
}