diff Agendas/trunk/src/Agendas.Repositories.Memory/RepositoryBase.cs @ 56:65bbcdd5d357

Pasando la responsabilidad de generar el Id al repositorio
author nelopauselli
date Mon, 16 May 2011 20:15:05 -0300
parents 475be11edf56
children 2d1adbaf0373
line wrap: on
line diff
--- 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<T>
+	public class RepositoryBase<T> where T : Identificable
 	{
 		protected static readonly IDictionary<Guid, T> Objects = new Dictionary<Guid, T>();
+
+		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