public GeocacheCollection GetCollection(string name, bool createIfNotExists = false) { GeocacheCollection result = null; if (!string.IsNullOrEmpty(name)) { lock (this) { if (_dbcon != null) { using (var db = new NPoco.Database(_dbcon.Connection, NPoco.DatabaseType.SQLite)) { result = db.FirstOrDefault <GeocacheCollection>("where Name like @0", name); if (result == null && createIfNotExists) { //just the lazy way var record = db.FirstOrDefault <GeocacheCollection>("order by CollectionID desc limit 1"); result = new GeocacheCollection(); result.Name = name; result.CollectionID = record == null ? 1 : record.CollectionID + 1; db.Insert(result); } } } } } return(result); }
public Database(string fn) { FileName = fn; this.LogCollection = new LogCollection(this); this.LogImageCollection = new LogImageCollection(this); this.WaypointCollection = new WaypointCollection(this); this.UserWaypointCollection = new UserWaypointCollection(this); this.GeocacheImageCollection = new GeocacheImageCollection(this); this.GeocacheCollection = new GeocacheCollection(this); }