view Agendas/trunk/src/Agendas.Web/Controllers/AgendaController.cs @ 10:c62b77fc33f4

website inicial
author nelo@MTEySS.neluz.int
date Sun, 13 Mar 2011 18:51:06 -0300
parents
children 05996fa19e04
line wrap: on
line source

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Agendas.Web.Models;
using AltNetHispano.Agendas.Domain;
using AltNetHispano.Agendas.Domain.Exceptions;

namespace Agendas.Web.Controllers
{
    public class AgendaController : Controller
    {
        public ActionResult Index()
        {
            var model = GetIndexModel();
            return View(model);
        }

        private static AgendaIndexModel GetIndexModel()
        {
            var agenda = AgendaFactory.GetAgenda();

            return new AgendaIndexModel
                       {
                           ProximosEventos = from e in agenda.GetEventosPublicados()
                                             select new EventoDto {Id = e.Id.ToString(), Titulo = e.Titulo}
                       };
        }

        public ActionResult New()
        {
            return View();
        }

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

                try
                {
                    agenda.Publicar(new Van {Titulo = model.Titulo, Ponente = model.Ponente, Fecha = model.Fecha});

                    return View("Index", GetIndexModel());
                }
                catch (ValidationException ex)
                {
                    ModelState.AddModelError("error", ex.ToString());
                }
            }
            return View(model);
        }

        
    }
}