Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Find with string id

  • Loading branch information...
commit 60d25cae332f28c94aeec3db7eb0679c8100fa55 1 parent 10c2142
@soitgoes authored
View
21 LoveSeat.Interfaces/IRepository.cs
@@ -1,11 +1,12 @@
-using System;
-using LoveSeat.Interfaces;
-
-namespace LoveSeat.Interfaces
-{
- public interface IRepository<T> where T : IBaseObject
- {
- void Save(T item);
- T Find(Guid id);
- }
+using System;
+using LoveSeat.Interfaces;
+
+namespace LoveSeat.Interfaces
+{
+ public interface IRepository<T> where T : IBaseObject
+ {
+ void Save(T item);
+ T Find(Guid id);
+ T Find(string id);
+ }
}
View
76 LoveSeat.Repository/CouchRepository.cs
@@ -1,36 +1,42 @@
-using System;
-using LoveSeat.Interfaces;
-
-namespace LoveSeat.Repositories
-{
- public class CouchRepository<T> : IRepository<T> where T : IBaseObject
- {
- protected readonly CouchDatabase db = null;
- public CouchRepository(CouchDatabase db)
- {
- this.db = db;
- }
-
- public virtual void Save(T item)
- {
- if (item.Id == "")
- item.Id = Guid.NewGuid().ToString();
- var doc = new Document<T>(item);
- db.SaveDocument(doc);
- }
-
- public virtual T Find(Guid id)
- {
- return db.GetDocument<T>(id.ToString());
- }
-
- /// <summary>
- /// Repository methods don't have the business validation. Use the service methods to enforce.
- /// </summary>
- /// <param name="obj"></param>
- public virtual void Delete(T obj)
- {
- db.DeleteDocument(obj.Id.ToString(), obj.Rev);
- }
- }
+using System;
+using LoveSeat.Interfaces;
+
+namespace LoveSeat.Repositories
+{
+ public class CouchRepository<T> : IRepository<T> where T : IBaseObject
+ {
+ protected readonly CouchDatabase db = null;
+
+ public CouchRepository(CouchDatabase db)
+ {
+ this.db = db;
+ }
+
+ public virtual void Save(T item)
+ {
+ if (item.Id == "")
+ item.Id = Guid.NewGuid().ToString();
+ var doc = new Document<T>(item);
+ db.SaveDocument(doc);
+ }
+
+ public virtual T Find(Guid id)
+ {
+ return db.GetDocument<T>(id.ToString());
+ }
+
+ public virtual T Find(string id)
+ {
+ return db.GetDocument<T>(id);
+ }
+
+ /// <summary>
+ /// Repository methods don't have the business validation. Use the service methods to enforce.
+ /// </summary>
+ /// <param name="obj"></param>
+ public virtual void Delete(T obj)
+ {
+ db.DeleteDocument(obj.Id.ToString(), obj.Rev);
+ }
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.