Update the repositories to use the new interface
This commit is contained in:
@@ -11,33 +11,30 @@ namespace skydiveLogs_api.Data
|
|||||||
{
|
{
|
||||||
public class GearRepository : IGearRepository
|
public class GearRepository : IGearRepository
|
||||||
{
|
{
|
||||||
|
public GearRepository(IDataProvider dataProvider)
|
||||||
|
{
|
||||||
|
_dataProvider = dataProvider;
|
||||||
|
_col = _dataProvider.CollOfGear;
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<Gear> GetAll()
|
public IEnumerable<Gear> GetAll()
|
||||||
{
|
{
|
||||||
IEnumerable<Gear> result = new List<Gear>();
|
var results = _col.FindAll().ToList();
|
||||||
|
_dataProvider.Close();
|
||||||
|
|
||||||
using (var db = new LiteDatabase(@".\Data\MyData.db"))
|
return results;
|
||||||
{
|
|
||||||
var col = db.GetCollection<Gear>("Gear");
|
|
||||||
|
|
||||||
result = col.FindAll().ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gear GetById(int id)
|
public Gear GetById(int id)
|
||||||
{
|
{
|
||||||
Gear result;
|
var result = _col.FindById(new BsonValue(id));
|
||||||
|
_dataProvider.Close();
|
||||||
using (var db = new LiteDatabase(@".\Data\MyData.db"))
|
|
||||||
{
|
|
||||||
var col = db.GetCollection<Gear>("Gear");
|
|
||||||
|
|
||||||
result = col.FindById(new BsonValue(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly IDataProvider _dataProvider;
|
||||||
|
|
||||||
|
private readonly LiteCollection<Gear> _col;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,30 +11,24 @@ namespace skydiveLogs_api.Data
|
|||||||
{
|
{
|
||||||
public class JumpRepository : IJumpRepository
|
public class JumpRepository : IJumpRepository
|
||||||
{
|
{
|
||||||
|
public JumpRepository(IDataProvider dataProvider)
|
||||||
|
{
|
||||||
|
_dataProvider = dataProvider;
|
||||||
|
_col = _dataProvider.CollOfJump;
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<Jump> GetAll()
|
public IEnumerable<Jump> GetAll()
|
||||||
{
|
{
|
||||||
IEnumerable<Jump> result = new List<Jump>();
|
var results = _col.FindAll().ToList();
|
||||||
|
_dataProvider.Close();
|
||||||
|
|
||||||
using (var db = new LiteDatabase(@".\Data\MyData.db"))
|
return results;
|
||||||
{
|
|
||||||
var col = db.GetCollection<Jump>("Jump");
|
|
||||||
|
|
||||||
result = col.FindAll().ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Jump GetById(int id)
|
public Jump GetById(int id)
|
||||||
{
|
{
|
||||||
Jump result;
|
var result = _col.FindById(new BsonValue(id));
|
||||||
|
_dataProvider.Close();
|
||||||
using (var db = new LiteDatabase(@".\Data\MyData.db"))
|
|
||||||
{
|
|
||||||
var col = db.GetCollection<Jump>("Jump");
|
|
||||||
|
|
||||||
result = col.FindById(new BsonValue(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -45,12 +39,8 @@ namespace skydiveLogs_api.Data
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var db = new LiteDatabase(@".\Data\MyData.db"))
|
_col.Insert(newJump);
|
||||||
{
|
_dataProvider.Close();
|
||||||
var col = db.GetCollection<Jump>("Jump");
|
|
||||||
|
|
||||||
col.Insert(newJump);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -59,5 +49,9 @@ namespace skydiveLogs_api.Data
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly IDataProvider _dataProvider;
|
||||||
|
|
||||||
|
private readonly LiteCollection<Jump> _col;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,32 +11,29 @@ namespace skydiveLogs_api.Data
|
|||||||
{
|
{
|
||||||
public class JumpTypeRepository : IJumpTypeRepository
|
public class JumpTypeRepository : IJumpTypeRepository
|
||||||
{
|
{
|
||||||
|
public JumpTypeRepository(IDataProvider dataProvider)
|
||||||
|
{
|
||||||
|
_dataProvider = dataProvider;
|
||||||
|
_col = _dataProvider.CollOfJumpType;
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<JumpType> GetAll()
|
public IEnumerable<JumpType> GetAll()
|
||||||
{
|
{
|
||||||
IEnumerable<JumpType> result = new List<JumpType>();
|
var results = _col.FindAll().ToList();
|
||||||
|
_dataProvider.Close();
|
||||||
|
|
||||||
using (var db = new LiteDatabase(@".\Data\MyData.db"))
|
return results;
|
||||||
{
|
|
||||||
var col = db.GetCollection<JumpType>("JumpType");
|
|
||||||
|
|
||||||
result = col.FindAll().ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public JumpType GetById(int id)
|
public JumpType GetById(int id)
|
||||||
{
|
{
|
||||||
JumpType result;
|
var result = _col.FindById(new BsonValue(id));
|
||||||
|
_dataProvider.Close();
|
||||||
using (var db = new LiteDatabase(@".\Data\MyData.db"))
|
|
||||||
{
|
|
||||||
var col = db.GetCollection<JumpType>("JumpType");
|
|
||||||
|
|
||||||
result = col.FindById(new BsonValue(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
private readonly IDataProvider _dataProvider;
|
||||||
|
|
||||||
|
private readonly LiteCollection<JumpType> _col;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user