diff Agendas/trunk/src/Agendas.Web/Controllers/PersonaController.cs @ 144:a2b14da4902f

Alta y modificación de ponentes (personas)
author Nelo@Guinea.neluz.int
date Mon, 01 Aug 2011 10:25:23 -0300
parents
children 23aaf98b8377
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Web/Controllers/PersonaController.cs	Mon Aug 01 10:25:23 2011 -0300
@@ -0,0 +1,80 @@
+using System;
+using System.Linq;
+using System.Web.Mvc;
+using AltNetHispano.Agendas.Factories;
+using AltNetHispano.Agendas.Web.Models;
+
+namespace AltNetHispano.Agendas.Web.Controllers
+{
+    public class PersonaController : Controller
+    {
+        public ActionResult Index()
+        {
+            var personas = AgendaFactory.GetPersonaService();
+
+            var model = new PersonaIndexModel {Items = from p in personas.GetAll() select new PersonaDto{Id=p.Id, Nombre = p.Nombre}};
+
+            return View(model);
+        }
+
+        public ActionResult Nueva()
+        {
+            return View();
+        }
+
+        [HttpPost]
+        public ActionResult Nueva(PersonaNewModel model)
+        {
+            if (ModelState.IsValid)
+            {
+                var personas = AgendaFactory.GetPersonaService();
+                var r = personas.Add(model.Nombre, model.Twitter, model.EMail);
+                if (r.Succeful)
+                {
+                    this.AddNotification("Los datos fueron guardados");
+                    return RedirectToAction("Index");
+                }
+                else
+                    this.AddError(r.Message);
+            }
+
+            return View(model);
+        }
+
+        public ActionResult Modificar(string id)
+        {
+            var personas = AgendaFactory.GetPersonaService();
+
+            var persona = personas.GetById(new Guid(id));
+            if (persona==null)
+            {
+                this.AddError("No se encontró la persona que intenta modificar");
+                return RedirectToAction("Index");
+            }
+
+            var model = new PersonaEditModel
+                            {Id = persona.Id.ToString(), Nombre = persona.Nombre, Twitter = persona.Twitter, EMail = persona.Mail};
+            
+            return View(model);
+        }
+
+        [HttpPost]
+        public ActionResult Modificar(PersonaEditModel model)
+        {
+            if (ModelState.IsValid)
+            {
+                var personas = AgendaFactory.GetPersonaService();
+                var r = personas.Update(new Guid(model.Id), model.Nombre, model.Twitter, model.EMail);
+                if (r.Succeful)
+                {
+                    this.AddNotification("Los datos fueron guardados");
+                    return RedirectToAction("Index");
+                }
+                else
+                    this.AddError(r.Message);
+            }
+
+            return View(model);
+        }
+    }
+}
\ No newline at end of file