Mercurial > altnet-hispano
view 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 |
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 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); } [CustomAuthorize(Roles = Roles.Administrador)] public ActionResult Nueva() { var model = new PersonaNewModel(); return View("Defaulteditor", model); } [HttpPost] [CustomAuthorize(Roles = Roles.Administrador)] public ActionResult Nueva(PersonaNewModel model) { if (ModelState.IsValid) { var personas = AgendaFactory.GetPersonaService(); var r = personas.Add(model.Nombre, model.Twitter, model.EMail,model.Blog); if (r.Succeful) { this.AddNotification("Los datos fueron guardados"); return RedirectToAction("Index"); } this.AddError(r.Message); } return View("Defaulteditor", model); } [CustomAuthorize(Roles = Roles.Administrador)] 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, Blog = persona.Blog }; return View("Defaulteditor", model); } [HttpPost] [CustomAuthorize(Roles = Roles.Administrador)] 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, model.Blog); if (r.Succeful) { this.AddNotification("Los datos fueron guardados"); return RedirectToAction("Index"); } this.AddError(r.Message); } return View("Defaulteditor", model); } } }