Mercurial > altnet-hispano
changeset 211:75eefd82760f
Combinar
author | juanjose.montesdeocaarbos |
---|---|
date | Fri, 26 Aug 2011 07:27:01 -0300 |
parents | 5cc7bc973ffc (current diff) a36a76bd6ec3 (diff) |
children | 6944c54f834f |
files | |
diffstat | 19 files changed, 174 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgtags Fri Aug 26 07:27:01 2011 -0300 @@ -0,0 +1,1 @@ +5346c0500594f1ba8c32573c827ea1925f6deda9 deploy pre 1.0
--- a/Agendas/trunk/src/Agendas.Domain/Repositories/IEventoRepository.cs Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Domain/Repositories/IEventoRepository.cs Fri Aug 26 07:27:01 2011 -0300 @@ -12,5 +12,6 @@ Evento GetPropuestaByTitulo(string titulo); void Save(Evento evento); void Update(Evento evento); + bool ExistePonente(Persona ponente); } } \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Domain/Repositories/IPersonaRepository.cs Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Domain/Repositories/IPersonaRepository.cs Fri Aug 26 07:27:01 2011 -0300 @@ -11,5 +11,6 @@ Cuenta GetCuenta(IdentityProviderEnum identityProvider, string username); Persona GetByTwitter(string username); Persona Get(Guid id); + void Delete(Persona persona); } } \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Domain/Services/PersonaService.cs Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Domain/Services/PersonaService.cs Fri Aug 26 07:27:01 2011 -0300 @@ -8,10 +8,12 @@ public class PersonaService { private readonly IPersonaRepository _personaRepository; + private readonly IEventoRepository _eventoRepository; - public PersonaService(IPersonaRepository personaRepository) + public PersonaService(IPersonaRepository personaRepository, IEventoRepository eventoRepository) { _personaRepository = personaRepository; + _eventoRepository = eventoRepository; } public bool CreateIfNotExist(IdentityProviderEnum identityProvider, string username, string nombre) @@ -126,5 +128,22 @@ return new Resultado(true, "Datos actualizados"); } + + public Resultado Delete(Guid id) + { + var persona = _personaRepository.Get(id); + if (persona == null) + return new Resultado(false, string.Format("No se pudo encontrar la persona cuyo Id sea {0}", id)); + + var existeEnEvento = _eventoRepository.ExistePonente(persona); + if (existeEnEvento) + return new Resultado(false, + string.Format( + "La persona {0} está asociada a un Evento por lo que es imposible eliminarla.", + persona.Nombre)); + + _personaRepository.Delete(persona); + return new Resultado(true, ""); + } } } \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Factories/AgendaFactory.cs Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Factories/AgendaFactory.cs Fri Aug 26 07:27:01 2011 -0300 @@ -33,9 +33,15 @@ return new PersonaRepository(sessionFactory); } - public static PersonaService GetPersonaService() - { - return new PersonaService(GetPersonaRepository()); - } + public static IEventoRepository GetEventoRespository() + { + ISessionFactory sessionFactory = NhHelper.GetSessionFactory(); + return new EventoRepository(sessionFactory); + } + + public static PersonaService GetPersonaService() + { + return new PersonaService(GetPersonaRepository(), GetEventoRespository()); + } } } \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Repositories.Memory/EventoRepository.cs Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Repositories.Memory/EventoRepository.cs Fri Aug 26 07:27:01 2011 -0300 @@ -13,7 +13,12 @@ //nada que hacer en este método para este repositorio } - public IList<Evento> GetByState(EventoState state) + public bool ExistePonente(Persona ponente) + { + return Objects.Values.Any(ev => ev.Ponente == ponente); + } + + public IList<Evento> GetByState(EventoState state) { return Objects.Values.Where(e => e.Estado == state).ToList(); }
--- a/Agendas/trunk/src/Agendas.Repositories.NHibernate/EventoRepository.cs Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Repositories.NHibernate/EventoRepository.cs Fri Aug 26 07:27:01 2011 -0300 @@ -40,7 +40,12 @@ //No es necesario implementarlo } - public IList<Evento> GetByState(EventoState state) + public bool ExistePonente(Persona ponente) + { + return Session.QueryOver<Evento>().Where(ev => ev.Ponente == ponente).RowCount() > 0; + } + + public IList<Evento> GetByState(EventoState state) { return Session.QueryOver<Evento>().Where(e => e.Estado == state).List(); }
--- a/Agendas/trunk/src/Agendas.Repositories.NHibernate/PonenteRepository.cs Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Repositories.NHibernate/PonenteRepository.cs Fri Aug 26 07:27:01 2011 -0300 @@ -33,5 +33,10 @@ { return Session.QueryOver<Persona>().Where(p => p.Twitter == username).SingleOrDefault(); } + + public void Delete(Persona persona) + { + Session.Delete(persona); + } } } \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Tests/Cruds/PersonaCrud.cs Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Tests/Cruds/PersonaCrud.cs Fri Aug 26 07:27:01 2011 -0300 @@ -12,11 +12,13 @@ private readonly IPersonaRepository _personaRepository; private readonly Func<IDisposable> _requestEmulator; private readonly PersonaService _personaService; + private readonly IEventoRepository _eventoRepository; - public PersonaCrud(Func<IPersonaRepository> createpersonaRepository, Func<IDisposable> requestEmulator) + public PersonaCrud(Func<IPersonaRepository> createpersonaRepository, Func<IDisposable> requestEmulator, Func<IEventoRepository> createEventoRespository) { _personaRepository = createpersonaRepository.Invoke(); - _personaService = new PersonaService(_personaRepository); + _eventoRepository = createEventoRespository.Invoke(); + _personaService = new PersonaService(_personaRepository, _eventoRepository); _requestEmulator = requestEmulator; } @@ -118,5 +120,20 @@ Assert.AreEqual("Nelo Mariano Pauselli", persona.Nombre); } } + public void Delete() + { + var personaId = CreateUsuario(); + using (_requestEmulator.Invoke()) + { + var persona = _personaRepository.Get(personaId); + Assert.IsNotNull(persona); + _personaService.Delete(personaId); + } + using (_requestEmulator.Invoke()) + { + var persona = _personaRepository.Get(personaId); + Assert.IsNull(persona); + } + } } } \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Tests/Cruds/PersonaCrudMemoryTests.cs Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Tests/Cruds/PersonaCrudMemoryTests.cs Fri Aug 26 07:27:01 2011 -0300 @@ -30,7 +30,8 @@ [SetUp] public void CreateCrud() { - _test = new PersonaCrud(() => new PersonaRepository(), () => new Mock<IDisposable>().Object); + _test = new PersonaCrud(() => new PersonaRepository(), () => new Mock<IDisposable>().Object, + () => new EventoRepository()); } #endregion @@ -64,5 +65,11 @@ { _test.Update(); } + + [Test] + public void Delete() + { + _test.Delete(); + } } } \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Tests/Cruds/PersonaCrudNhTests.cs Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Tests/Cruds/PersonaCrudNhTests.cs Fri Aug 26 07:27:01 2011 -0300 @@ -32,7 +32,8 @@ public void CreateCrud() { ISessionFactory sessionFactory = NhHelper.GetSessionFactory(); - _test = new PersonaCrud(() => new PersonaRepository(sessionFactory), () => new RequestEmulator(sessionFactory)); + _test = new PersonaCrud(() => new PersonaRepository(sessionFactory), () => new RequestEmulator(sessionFactory), + () => new EventoRepository(sessionFactory)); } #endregion @@ -66,5 +67,11 @@ { _test.Update(); } + + [Test] + public void Delete() + { + _test.Delete(); + } } } \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Tests/PersonaServiceTests.cs Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Tests/PersonaServiceTests.cs Fri Aug 26 07:27:01 2011 -0300 @@ -18,7 +18,7 @@ Persona persona=null; personaRepository.Setup(r => r.Save(It.IsAny<Persona>())).Callback<Persona>(p => persona = p); - var personaService = new PersonaService(personaRepository.Object); + var personaService = new PersonaService(personaRepository.Object, DefaultEventoRepository); Assert.IsTrue(personaService.CreateIfNotExist(IdentityProviderEnum.Twitter, "nelopauselli", "Nelo Pauselli")); personaRepository.Verify(r=>r.Save(It.IsAny<Persona>()), Times.Once()); @@ -43,7 +43,7 @@ var personaRepository = DefaultPersonaRepository; personaRepository.Save(new Persona("Mariano Pauselli", "marianopauselli@gmail.com", "marianopauselli", "http://marianopauselli.blogspot.com")); - var personaService = new PersonaService(personaRepository); + var personaService = new PersonaService(personaRepository, DefaultEventoRepository); Assert.IsTrue(personaService.CreateIfNotExist(IdentityProviderEnum.Twitter, "marianopauselli", "Mariano Pauselli")); @@ -66,7 +66,7 @@ { var personaRepository = DefaultPersonaRepository; - var personaService = new PersonaService(personaRepository); + var personaService = new PersonaService(personaRepository, DefaultEventoRepository); var r = personaService.Add("Mariano Pauselli", "marianopauselli", string.Empty, string.Empty, null); Assert.IsTrue(r.Succeful); @@ -97,8 +97,8 @@ var p1 = personaRepository.GetByTwitter("nelopauselli"); Assert.IsNotNull(p1); Assert.AreEqual(1, p1.Cuentas.Count()); - - var personaService = new PersonaService(personaRepository); + + var personaService = new PersonaService(personaRepository, DefaultEventoRepository); personaService.AddCuenta(IdentityProviderEnum.Google, "nelopauselli"); @@ -136,10 +136,51 @@ public void Modificar_persona_inexistente() { var personaRepository = DefaultPersonaRepository; - var personaService = new PersonaService(personaRepository); + var personaService = new PersonaService(personaRepository, DefaultEventoRepository); var r = personaService.Update(new Guid(), "Mariano Pauselli", "marianopauselli", "marianopauselli@gmail.com", string.Empty, null); Assert.IsFalse(r.Succeful); } + + [Test] + public void Eliminar_persona_no_asociado_van() + { + var personaRepository = DefaultPersonaRepository; + + var personaService = new PersonaService(personaRepository, DefaultEventoRepository); + var r = personaService.Add("Alejandro Labra", "alabras", "alejandro.labra@gmail.com", string.Empty, null); + Assert.IsTrue(r.Succeful); + + var persona = personaRepository.GetByNombre("Alejandro Labra"); + Assert.IsNotNull(persona); + + var delete = personaService.Delete(persona.Id); + Assert.IsTrue(delete.Succeful); + } + + [Test] + public void Eliminar_persona_asociado_vans() + { + var publicador = new Mock<IPublicador>(); + var personaService = new PersonaService(DefaultPersonaRepository, DefaultEventoRepository); + + var agenda = new Agenda(publicador.Object, DefaultEventoRepository, DefaultPersonaRepository); + + var fechaInicio = DateTime.Now.ToUniversalTime(); + var fechaTermino = fechaInicio.AddHours(2); + agenda.Agendar("Van para publicar", TestsHelper.GetOrCreatePonente("alabra"), fechaInicio, fechaTermino, + "http://groups.google.com/group/altnet-hispano/browse_thread/thread/65d6d26eb381386e", TipoEvento.Van); + + Assert.AreEqual(0, agenda.GetEventosActivos(EventoPropuestoState.GetInstance()).Count); + + var eventos = agenda.GetEventosActivos(); + Assert.AreEqual(1, eventos.Count); + + var evento = eventos[0]; + Assert.IsNotNull(evento.Ponente); + + var delete = personaService.Delete(evento.Ponente.Id); + Assert.IsFalse(delete.Succeful); + } } } \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Web.Tests/AutorizationsTests.cs Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web.Tests/AutorizationsTests.cs Fri Aug 26 07:27:01 2011 -0300 @@ -92,7 +92,8 @@ "EventoController.Agendar", "EventoController.Confirmar", "EventoController.Nuevo", "EventoController.Publicar", "EventoController.Modificar", "EventoController.Proponer", "EventoController.Cancelar", "EventoController.Descartar", "EventoController.ReAgendar", - "EventoController.ReProponer", "PersonaController.Nueva", "PersonaController.Modificar" + "EventoController.ReProponer", "PersonaController.Nueva", "PersonaController.Modificar", + "PersonaController.Quitar" }; VerficarAccionesSeguras(acciones, Roles.Administrador, "debe ser de uso exclusivo de los administradores");
--- a/Agendas/trunk/src/Agendas.Web/Content/Site.css Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Content/Site.css Fri Aug 26 07:27:01 2011 -0300 @@ -115,7 +115,9 @@ } #main { - width: 794px; + /* este width es para cuando está la columna de patrocinadores, que en esta versión no está incluido + por lo que se comenta el width para que use el que hereda de page. + width: 794px;*/ float: left; font-size: 1.4em; line-height:120%; @@ -128,6 +130,7 @@ margin: 20px 0 0; padding: 10px 0; background: transparent url("themes/altnethispano/images/ul_topsponsors_li.gif") repeat-x 0 0; + text-align: center; } .userGroupLogo { @@ -275,6 +278,16 @@ color: #ff0000; } +.validation-summary-errors ul +{ + list-style-type:none; +} + +.validation-summary-errors li +{ + font-weight: normal; +} + .validation-summary-valid { display: none;
--- a/Agendas/trunk/src/Agendas.Web/Controllers/AccountController.cs Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Controllers/AccountController.cs Fri Aug 26 07:27:01 2011 -0300 @@ -23,15 +23,18 @@ return View(); } - public ActionResult TwitterLogOn() + public ActionResult TwitterLogOn(string returnUrl) { var oAuth = new OAuthTwitter(); if (Request["oauth_token"] == null) { var action = Url.Action("TwitterLogOn"); + if (!string.IsNullOrWhiteSpace(returnUrl)) + action += "?ReturnUrl=" + returnUrl; + var url = Request.Url.Scheme + "://" + Request.Url.Host + - (Request.Url.Port != 80 ? ":" + Request.Url.Port : string.Empty) + action; + (Request.Url.Port != 80 ? ":" + Request.Url.Port : string.Empty) + action; return Redirect(oAuth.AuthorizationLinkGet(url).ToString()); } @@ -58,6 +61,9 @@ personaService.CreateIfNotExist(IdentityProviderEnum.Twitter, username, nombre); _formsService.SignIn(Identification.Map[(int)IdentityProviderEnum.Twitter]+username, false); + + if (!string.IsNullOrWhiteSpace(returnUrl)) + return Redirect(returnUrl); return RedirectToAction("Index", "Home"); }
--- a/Agendas/trunk/src/Agendas.Web/Controllers/EventoController.cs Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Controllers/EventoController.cs Fri Aug 26 07:27:01 2011 -0300 @@ -239,7 +239,7 @@ this.AddWarning(log.WarningMessage); return RedirectToAction("Index"); } - ModelState.AddModelError("error", r.ToString()); + ModelState.AddModelError(string.Empty, r.Message); } return actionresultOnFail.Invoke(model); }
--- a/Agendas/trunk/src/Agendas.Web/Controllers/PersonaController.cs Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Controllers/PersonaController.cs Fri Aug 26 07:27:01 2011 -0300 @@ -87,5 +87,20 @@ return View("Defaulteditor", model); } + + [CustomAuthorize(Roles = Roles.Administrador)] + public ActionResult Quitar(string id) + { + var personas = AgendaFactory.GetPersonaService(); + var result = personas.Delete(new Guid(id)); + if (result.Succeful) + { + this.AddNotification("Se ha eliminado correctamente a la persona"); + + } + this.AddError(result.Message); + + return RedirectToAction("Index"); + } } } \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Web/Views/Account/LogOn.cshtml Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Views/Account/LogOn.cshtml Fri Aug 26 07:27:01 2011 -0300 @@ -12,7 +12,7 @@ <br /> <table border="0"> <tr> - <td><a href="@Url.Action("TwitterLogOn")"><img src="@Url.Content("~/Content/twitter/sign-in-with-twitter-d.png")" alt="Sign in with twitter" /></a></td> + <td><a href="@Url.Action("TwitterLogOn", new {returnUrl = Request["ReturnUrl"]})"><img src="@Url.Content("~/Content/twitter/sign-in-with-twitter-d.png")" alt="Sign in with twitter" /></a></td> <td>Identifíquese utilizando su cuenta de twitter</td> </tr> </table>
--- a/Agendas/trunk/src/Agendas.Web/Views/Shared/DefaultEditor.cshtml Fri Aug 26 07:26:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Views/Shared/DefaultEditor.cshtml Fri Aug 26 07:27:01 2011 -0300 @@ -8,7 +8,7 @@ @using (Html.BeginForm()) { - @Html.ValidationSummary(true, @LayoutResources.ValidationSummaryDefault) + @Html.ValidationSummary(true) <div> <fieldset> <legend>@Html.GetLegendForModel()</legend>