# HG changeset patch # User nelopauselli # Date 1305587705 10800 # Node ID 65bbcdd5d35799d0e481ca6a76a6558f2c722f8c # Parent 39f5258ebdcf384da67bb1f03289283ad1a4f228 Pasando la responsabilidad de generar el Id al repositorio diff -r 39f5258ebdcf -r 65bbcdd5d357 Agendas/trunk/src/Agendas.Domain/Agendas.Domain.csproj --- a/Agendas/trunk/src/Agendas.Domain/Agendas.Domain.csproj Mon May 16 20:10:45 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Domain/Agendas.Domain.csproj Mon May 16 20:15:05 2011 -0300 @@ -46,6 +46,7 @@ + diff -r 39f5258ebdcf -r 65bbcdd5d357 Agendas/trunk/src/Agendas.Domain/Evento.cs --- a/Agendas/trunk/src/Agendas.Domain/Evento.cs Mon May 16 20:10:45 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Domain/Evento.cs Mon May 16 20:15:05 2011 -0300 @@ -3,21 +3,19 @@ namespace AltNetHispano.Agendas.Domain { - public class Evento + public class Evento : Identificable { private readonly IList _tracks; private IList _enlaces; public Evento(string titulo) { - Id = Guid.NewGuid(); Titulo = titulo; _enlaces = new List(); _tracks = new List(); } - public Guid Id { get; private set; } public string Titulo { get; private set; } public DateTime? Fecha { get; private set; } public string Sintesis { get; private set; } diff -r 39f5258ebdcf -r 65bbcdd5d357 Agendas/trunk/src/Agendas.Domain/Identificable.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Domain/Identificable.cs Mon May 16 20:15:05 2011 -0300 @@ -0,0 +1,9 @@ +using System; + +namespace AltNetHispano.Agendas.Domain +{ + public class Identificable + { + public Guid Id { get; private set; } + } +} \ No newline at end of file diff -r 39f5258ebdcf -r 65bbcdd5d357 Agendas/trunk/src/Agendas.Domain/Ponente.cs --- a/Agendas/trunk/src/Agendas.Domain/Ponente.cs Mon May 16 20:10:45 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Domain/Ponente.cs Mon May 16 20:15:05 2011 -0300 @@ -1,8 +1,6 @@ -using System; - -namespace AltNetHispano.Agendas.Domain +namespace AltNetHispano.Agendas.Domain { - public class Ponente + public class Ponente : Identificable { public Ponente(string nombre, string mail, string twitter, string blog) : this(nombre) @@ -14,12 +12,9 @@ public Ponente(string nombre) { - Id = Guid.NewGuid(); Nombre = nombre; } - public Guid Id { get; private set; } - public string Nombre { get; private set; } public string Mail { get; private set; } diff -r 39f5258ebdcf -r 65bbcdd5d357 Agendas/trunk/src/Agendas.Repositories.Memory/EventoRepository.cs --- a/Agendas/trunk/src/Agendas.Repositories.Memory/EventoRepository.cs Mon May 16 20:10:45 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Repositories.Memory/EventoRepository.cs Mon May 16 20:15:05 2011 -0300 @@ -8,12 +8,6 @@ { public class EventoRepository : RepositoryBase, IEventoRepository { - public void Save(Evento evento) - { - if (!Objects.Keys.Contains(evento.Id)) - Objects.Add(evento.Id, evento); - } - public void Update(Evento evento) { //nada que hacer en este método para este repositorio diff -r 39f5258ebdcf -r 65bbcdd5d357 Agendas/trunk/src/Agendas.Repositories.Memory/PonenteRepository.cs --- a/Agendas/trunk/src/Agendas.Repositories.Memory/PonenteRepository.cs Mon May 16 20:10:45 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Repositories.Memory/PonenteRepository.cs Mon May 16 20:15:05 2011 -0300 @@ -7,12 +7,6 @@ { public class PonenteRepository : RepositoryBase, IPonenteRepository { - public void Save(Ponente ponente) - { - if (!Objects.Keys.Contains(ponente.Id)) - Objects.Add(ponente.Id, ponente); - } - public Ponente GetByNombre(string nombre) { return Objects.Values.SingleOrDefault(p => p.Nombre == nombre); diff -r 39f5258ebdcf -r 65bbcdd5d357 Agendas/trunk/src/Agendas.Repositories.Memory/RepositoryBase.cs --- a/Agendas/trunk/src/Agendas.Repositories.Memory/RepositoryBase.cs Mon May 16 20:10:45 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Repositories.Memory/RepositoryBase.cs Mon May 16 20:15:05 2011 -0300 @@ -1,10 +1,24 @@ using System; using System.Collections.Generic; +using AltNetHispano.Agendas.Domain; namespace AltNetHispano.Agendas.Repositories.Memory { - public class RepositoryBase + public class RepositoryBase where T : Identificable { protected static readonly IDictionary Objects = new Dictionary(); + + public void Save(T obj) + { + if (obj.Id==Guid.Empty) + { + var setter = typeof (Identificable).GetProperty("Id"); + setter.SetValue(obj, Guid.NewGuid(), null); + } + + if (!Objects.Keys.Contains(obj.Id)) + Objects.Add(obj.Id, obj); + } + } } \ No newline at end of file