view Agendas/trunk/src/Agendas.Web/Controllers/EventoController.cs @ 116:53bcd338542b

acciones de confirmar y publicar desde la UI
author Nelo@Kenia.neluz.int
date Sun, 19 Jun 2011 13:00:02 -0300
parents 80c22175c9b5
children 7ef7e4bb71f6
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.GetEventosAgendados()
							orderby e.Fecha
							select new EventoDto
							{
								Id = e.Id.ToString(),
								Titulo = e.Titulo,
								Fecha = e.Fecha.Value,
								PuedeModificar = e.GetEstado().PuedePromover(Accion.Modificar),
								PuedeConfirmar = e.GetEstado().PuedePromover(Accion.Confirmar),
								PuedePublicar = e.GetEstado().PuedePromover(Accion.Publicar)
							}
	  };

      return View(model);
    }

    [Authorize]
    public ActionResult New()
    {
      return View(new EventoNewModel());
    }

    [HttpPost]
    [Authorize]
    public ActionResult New(EventoNewModel model)
    {
      if (ModelState.IsValid)
      {
        var agenda = AgendaFactory.GetAgenda();

        var r = agenda.Agendar(model.Titulo, model.Ponente, model.Fecha,
          model.UrlInvitacion, (TipoEvento)model.Tipo);
        if (r.Succeful)
          return RedirectToAction("Index");
        ModelState.AddModelError("error", r.ToString());
      }
      return View(model);
    }

    [Authorize]
    public ActionResult Edit(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.Nombre : string.Empty,
                      Fecha = evento.Fecha,
                      UrlInvitacion = evento.UrlInvitacion
                    };
      return View(model);
    }

	[Authorize]
	public ActionResult Confirm(string id)
	{
		var agenda = AgendaFactory.GetAgenda();
		agenda.Confirmar(new Guid(id));
		return RedirectToAction("Index");
	}

	[Authorize]
	public ActionResult Publish(string id)
	{
		var agenda = AgendaFactory.GetAgenda();
		agenda.Publicar(new Guid(id), 0, string.Empty);
		return RedirectToAction("Index");
	}

    [HttpPost]
    [Authorize]
    public ActionResult Edit(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)
          return RedirectToAction("Index");
        ModelState.AddModelError("error", r.ToString());
      }
      return View(model);
    }
  }
}