comparison 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
comparison
equal deleted inserted replaced
143:2dbb15f4510f 144:a2b14da4902f
1 using System;
2 using System.Linq;
3 using System.Web.Mvc;
4 using AltNetHispano.Agendas.Factories;
5 using AltNetHispano.Agendas.Web.Models;
6
7 namespace AltNetHispano.Agendas.Web.Controllers
8 {
9 public class PersonaController : Controller
10 {
11 public ActionResult Index()
12 {
13 var personas = AgendaFactory.GetPersonaService();
14
15 var model = new PersonaIndexModel {Items = from p in personas.GetAll() select new PersonaDto{Id=p.Id, Nombre = p.Nombre}};
16
17 return View(model);
18 }
19
20 public ActionResult Nueva()
21 {
22 return View();
23 }
24
25 [HttpPost]
26 public ActionResult Nueva(PersonaNewModel model)
27 {
28 if (ModelState.IsValid)
29 {
30 var personas = AgendaFactory.GetPersonaService();
31 var r = personas.Add(model.Nombre, model.Twitter, model.EMail);
32 if (r.Succeful)
33 {
34 this.AddNotification("Los datos fueron guardados");
35 return RedirectToAction("Index");
36 }
37 else
38 this.AddError(r.Message);
39 }
40
41 return View(model);
42 }
43
44 public ActionResult Modificar(string id)
45 {
46 var personas = AgendaFactory.GetPersonaService();
47
48 var persona = personas.GetById(new Guid(id));
49 if (persona==null)
50 {
51 this.AddError("No se encontró la persona que intenta modificar");
52 return RedirectToAction("Index");
53 }
54
55 var model = new PersonaEditModel
56 {Id = persona.Id.ToString(), Nombre = persona.Nombre, Twitter = persona.Twitter, EMail = persona.Mail};
57
58 return View(model);
59 }
60
61 [HttpPost]
62 public ActionResult Modificar(PersonaEditModel model)
63 {
64 if (ModelState.IsValid)
65 {
66 var personas = AgendaFactory.GetPersonaService();
67 var r = personas.Update(new Guid(model.Id), model.Nombre, model.Twitter, model.EMail);
68 if (r.Succeful)
69 {
70 this.AddNotification("Los datos fueron guardados");
71 return RedirectToAction("Index");
72 }
73 else
74 this.AddError(r.Message);
75 }
76
77 return View(model);
78 }
79 }
80 }