comparison Agendas/trunk/src/Agendas.Web/Controllers/PersonaController.cs @ 179:1deccd6c3cb2

Aplicando seguridad x roles en sitio web
author nelopauselli
date Mon, 08 Aug 2011 15:24:26 -0300
parents f17252543cbf
children 222362c29416
comparison
equal deleted inserted replaced
178:33e57fd1a6c9 179:1deccd6c3cb2
1 using System; 1 using System;
2 using System.Linq; 2 using System.Linq;
3 using System.Web.Mvc; 3 using System.Web.Mvc;
4 using AltNetHispano.Agendas.Domain;
4 using AltNetHispano.Agendas.Factories; 5 using AltNetHispano.Agendas.Factories;
5 using AltNetHispano.Agendas.Web.Models; 6 using AltNetHispano.Agendas.Web.Models;
6 7
7 namespace AltNetHispano.Agendas.Web.Controllers 8 namespace AltNetHispano.Agendas.Web.Controllers
8 { 9 {
15 var model = new PersonaIndexModel {Items = from p in personas.GetAll() select new PersonaDto{Id=p.Id, Nombre = p.Nombre}}; 16 var model = new PersonaIndexModel {Items = from p in personas.GetAll() select new PersonaDto{Id=p.Id, Nombre = p.Nombre}};
16 17
17 return View(model); 18 return View(model);
18 } 19 }
19 20
20 public ActionResult Nueva() 21 [CustomAuthorize(Roles = Roles.Administrador)]
22 public ActionResult Nueva()
21 { 23 {
22 var model = new PersonaNewModel(); 24 var model = new PersonaNewModel();
23 return View("Defaulteditor", model); 25 return View("Defaulteditor", model);
24 } 26 }
25 27
26 [HttpPost] 28 [HttpPost]
29 [CustomAuthorize(Roles = Roles.Administrador)]
27 public ActionResult Nueva(PersonaNewModel model) 30 public ActionResult Nueva(PersonaNewModel model)
28 { 31 {
29 if (ModelState.IsValid) 32 if (ModelState.IsValid)
30 { 33 {
31 var personas = AgendaFactory.GetPersonaService(); 34 var personas = AgendaFactory.GetPersonaService();
39 } 42 }
40 43
41 return View("Defaulteditor", model); 44 return View("Defaulteditor", model);
42 } 45 }
43 46
44 public ActionResult Modificar(string id) 47 [CustomAuthorize(Roles = Roles.Administrador)]
48 public ActionResult Modificar(string id)
45 { 49 {
46 var personas = AgendaFactory.GetPersonaService(); 50 var personas = AgendaFactory.GetPersonaService();
47 51
48 var persona = personas.GetById(new Guid(id)); 52 var persona = personas.GetById(new Guid(id));
49 if (persona==null) 53 if (persona==null)
63 67
64 return View("Defaulteditor", model); 68 return View("Defaulteditor", model);
65 } 69 }
66 70
67 [HttpPost] 71 [HttpPost]
68 public ActionResult Modificar(PersonaEditModel model) 72 [CustomAuthorize(Roles = Roles.Administrador)]
73 public ActionResult Modificar(PersonaEditModel model)
69 { 74 {
70 if (ModelState.IsValid) 75 if (ModelState.IsValid)
71 { 76 {
72 var personas = AgendaFactory.GetPersonaService(); 77 var personas = AgendaFactory.GetPersonaService();
73 var r = personas.Update(new Guid(model.Id), model.Nombre, model.Twitter, model.EMail, model.Blog); 78 var r = personas.Update(new Guid(model.Id), model.Nombre, model.Twitter, model.EMail, model.Blog);