Mercurial > altnet-hispano
changeset 144:a2b14da4902f
Alta y modificación de ponentes (personas)
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Domain/Persona.cs Mon Aug 01 09:41:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Domain/Persona.cs Mon Aug 01 10:25:23 2011 -0300 @@ -25,9 +25,9 @@ _cuentas = new List<Cuenta>(); } - public virtual string Nombre { get; private set; } + public virtual string Nombre { get; set; } - public virtual string Mail { get; private set; } + public virtual string Mail { get; set; } public virtual string Twitter { get; set; }
--- a/Agendas/trunk/src/Agendas.Domain/Repositories/IPersonaRepository.cs Mon Aug 01 09:41:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Domain/Repositories/IPersonaRepository.cs Mon Aug 01 10:25:23 2011 -0300 @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace AltNetHispano.Agendas.Domain.Repositories { @@ -9,5 +10,6 @@ void Save(Persona persona); Cuenta GetCuenta(IdentityProviderEnum identityProvider, string username); Persona GetByTwitter(string username); + Persona Get(Guid id); } } \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Domain/Resultado.cs Mon Aug 01 09:41:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Domain/Resultado.cs Mon Aug 01 10:25:23 2011 -0300 @@ -8,5 +8,6 @@ } public bool Succeful { get; private set; } - } + public string Message { get; internal set; } + } } \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Domain/Services/PersonaService.cs Mon Aug 01 09:41:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Domain/Services/PersonaService.cs Mon Aug 01 10:25:23 2011 -0300 @@ -1,4 +1,6 @@ -using System.Linq; +using System; +using System.Collections.Generic; +using System.Linq; using AltNetHispano.Agendas.Domain.Repositories; namespace AltNetHispano.Agendas.Domain.Services @@ -56,5 +58,37 @@ if (cuenta != null) persona.RemoveCuenta(cuenta); } + + public IEnumerable<Persona> GetAll() + { + return _personaRepository.GetAll(); + } + + public Persona GetById(Guid id) + { + return _personaRepository.Get(id); + } + + public Resultado Add(string nombre, string twitter, string mail) + { + var persona = new Persona(nombre) {Twitter = twitter, Mail = mail}; + _personaRepository.Save(persona); + + return new Resultado(true); + } + + public Resultado Update(Guid id, string nombre, string twitter, string mail) + { + var persona = _personaRepository.Get(id); + if (persona == null) + return new Resultado(false) + {Message = string.Format("No se pudo encontrar la persona cuyo Id sea {0}", id)}; + + persona.Nombre = nombre; + persona.Twitter = twitter; + persona.Mail = mail; + + return new Resultado(true); + } } } \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Repositories.NHibernate/RepositoryBase.cs Mon Aug 01 09:41:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Repositories.NHibernate/RepositoryBase.cs Mon Aug 01 10:25:23 2011 -0300 @@ -1,8 +1,10 @@ -using NHibernate; +using System; +using AltNetHispano.Agendas.Domain; +using NHibernate; namespace AltNetHispano.Agendas.Repositories.NHibernate { - public class RepositoryBase<T> + public class RepositoryBase<T> where T : Identificable { private readonly ISessionFactory _sessionFactory; @@ -17,5 +19,11 @@ { Session.Save(obj); } + + public T Get(Guid id) + { + return Session.QueryOver<T>().Where(i => i.Id == id).SingleOrDefault(); + } + } } \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Web/Agendas.Web.csproj Mon Aug 01 09:41:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Agendas.Web.csproj Mon Aug 01 10:25:23 2011 -0300 @@ -67,6 +67,7 @@ <Compile Include="Controllers\HistoricoController.cs" /> <Compile Include="Controllers\HomeController.cs" /> <Compile Include="Controllers\PerfilController.cs" /> + <Compile Include="Controllers\PersonaController.cs" /> <Compile Include="DataProviders.cs" /> <Compile Include="Global.asax.cs"> <DependentUpon>Global.asax</DependentUpon> @@ -80,6 +81,7 @@ <Compile Include="Models\EventoModelHelper.cs" /> <Compile Include="Models\HistoricoModel.cs" /> <Compile Include="Models\PerfilModel.cs" /> + <Compile Include="Models\PersonaModel.cs" /> <Compile Include="Models\PropuestaModel.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Services\FormsAuthenticationService.cs" /> @@ -204,6 +206,15 @@ <ItemGroup> <Content Include="Views\Shared\EditorTemplates\TipoEvento.cshtml" /> </ItemGroup> + <ItemGroup> + <Content Include="Views\Persona\Index.cshtml" /> + </ItemGroup> + <ItemGroup> + <Content Include="Views\Persona\Nueva.cshtml" /> + </ItemGroup> + <ItemGroup> + <Content Include="Views\Persona\Modificar.cshtml" /> + </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
--- a/Agendas/trunk/src/Agendas.Web/Controllers/EventoController.cs Mon Aug 01 09:41:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Controllers/EventoController.cs Mon Aug 01 10:25:23 2011 -0300 @@ -7,7 +7,7 @@ namespace AltNetHispano.Agendas.Web.Controllers { - public class EventoController : Controller + public class EventoController : Controller { public ActionResult Index() {
--- /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
--- a/Agendas/trunk/src/Agendas.Web/Models/EventoModel.cs Mon Aug 01 09:41:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Models/EventoModel.cs Mon Aug 01 10:25:23 2011 -0300 @@ -6,7 +6,7 @@ namespace AltNetHispano.Agendas.Web.Models { - public class EventoIndexModel + public class EventoIndexModel { public IEnumerable<EventoDto> ProximosEventos { get; set; } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Web/Models/PersonaModel.cs Mon Aug 01 10:25:23 2011 -0300 @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Web.Mvc; + +namespace AltNetHispano.Agendas.Web.Models +{ + public class PersonaIndexModel{ + public IEnumerable<PersonaDto> Items { get; set; } + } + + public class PersonaNewModel + { + [Required] + public string Nombre { get; set; } + + [Required] + public string Twitter { get; set; } + + [Required] + public string EMail { get; set; } + } + + public class PersonaEditModel + { + [Required] + [HiddenInput(DisplayValue = false)] + public string Id { get; set; } + + [Required] + public string Nombre { get; set; } + + [Required] + public string Twitter { get; set; } + + [Required] + public string EMail { get; set; } + } + + public class PersonaDto + { + public Guid Id { get; set; } + public string Nombre { get; set; } + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Web/Views/Persona/Index.cshtml Mon Aug 01 10:25:23 2011 -0300 @@ -0,0 +1,31 @@ +@model AltNetHispano.Agendas.Web.Models.PersonaIndexModel +<h2>Personas</h2> +<p> + Las personas registradas en la aplicación son: +</p> +<table> + <thead> + <tr> + <th>Nombre</th> + <th>Acciones</th> + </tr> + </thead> + <tbody> + @foreach (var item in Model.Items) + { + <tr> + <td>@item.Nombre</td> + <td> + @Html.ActionLink("Modificar", "Modificar", null, new { id = item.Id }, null) + <span> </span> + @Html.ActionLink("Quitar", "Quitar", null, new { id = item.Id }, null) + <span> </span> + </td> + </tr> + } + </tbody> +</table> + +<p> +@Html.ActionLink("Nueva", "Nueva") +</p>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Web/Views/Persona/Modificar.cshtml Mon Aug 01 10:25:23 2011 -0300 @@ -0,0 +1,29 @@ +@model AltNetHispano.Agendas.Web.Models.PersonaEditModel +<h2>Personas</h2> +<p> + Modifique los datos que desea corregir y presione guardar +</p> + +<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> +<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> + +<script type="text/javascript"> + $(document).ready(function () { + $("#Fecha").datepicker({ dateFormat: 'dd-mm-yy' }); + }); +</script> + +@using (Html.BeginForm()) +{ + @Html.ValidationSummary(true, "Los datos ingresados no son validos, por favor verifíquelos") + <div> + <fieldset> + <legend>Datos de la persona:</legend> + @Html.EditorForModel() + <p> + <input type="submit" value="Guardar" /> + @Html.ActionLink("Cancelar", "Index") + </p> + </fieldset> + </div> +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Web/Views/Persona/Nueva.cshtml Mon Aug 01 10:25:23 2011 -0300 @@ -0,0 +1,26 @@ +@model AltNetHispano.Agendas.Web.Models.PersonaNewModel +<h2>Personas</h2> +<p> + Complete los siguiente datos para registrar una nueva persona +</p> + +<link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" /> +<script src="@Url.Content("~/Scripts/jquery-ui.js")" type="text/javascript"></script> + +<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> +<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> + +@using (Html.BeginForm()) +{ + @Html.ValidationSummary(true, "Los datos ingresados no son validos, por favor verifíquelos") + <div> + <fieldset> + <legend>Datos de la persona:</legend> + @Html.EditorForModel() + <p> + <input type="submit" value="Guardar" /> + @Html.ActionLink("Cancelar", "Index") + </p> + </fieldset> + </div> +} \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Web/Views/Shared/_Menu.cshtml Mon Aug 01 09:41:29 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Views/Shared/_Menu.cshtml Mon Aug 01 10:25:23 2011 -0300 @@ -5,6 +5,7 @@ @if (Request.IsAuthenticated) { <li>@Html.ActionLink("Perfil", "Index", "Perfil")</li> + <li>@Html.ActionLink("Personas", "Index", "Persona")</li> } <li>@Html.ActionLink("About", "About", "Home")</li> </ul>