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 GearRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
_col = _dataProvider.CollOfGear;
|
||||
}
|
||||
|
||||
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"))
|
||||
{
|
||||
var col = db.GetCollection<Gear>("Gear");
|
||||
|
||||
result = col.FindAll().ToList();
|
||||
}
|
||||
|
||||
return result;
|
||||
return results;
|
||||
}
|
||||
|
||||
public Gear GetById(int id)
|
||||
{
|
||||
Gear result;
|
||||
|
||||
using (var db = new LiteDatabase(@".\Data\MyData.db"))
|
||||
{
|
||||
var col = db.GetCollection<Gear>("Gear");
|
||||
|
||||
result = col.FindById(new BsonValue(id));
|
||||
}
|
||||
var result = _col.FindById(new BsonValue(id));
|
||||
_dataProvider.Close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
private readonly LiteCollection<Gear> _col;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,30 +11,24 @@ namespace skydiveLogs_api.Data
|
||||
{
|
||||
public class JumpRepository : IJumpRepository
|
||||
{
|
||||
public JumpRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
_col = _dataProvider.CollOfJump;
|
||||
}
|
||||
|
||||
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"))
|
||||
{
|
||||
var col = db.GetCollection<Jump>("Jump");
|
||||
|
||||
result = col.FindAll().ToList();
|
||||
}
|
||||
|
||||
return result;
|
||||
return results;
|
||||
}
|
||||
|
||||
public Jump GetById(int id)
|
||||
{
|
||||
Jump result;
|
||||
|
||||
using (var db = new LiteDatabase(@".\Data\MyData.db"))
|
||||
{
|
||||
var col = db.GetCollection<Jump>("Jump");
|
||||
|
||||
result = col.FindById(new BsonValue(id));
|
||||
}
|
||||
var result = _col.FindById(new BsonValue(id));
|
||||
_dataProvider.Close();
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -45,12 +39,8 @@ namespace skydiveLogs_api.Data
|
||||
|
||||
try
|
||||
{
|
||||
using (var db = new LiteDatabase(@".\Data\MyData.db"))
|
||||
{
|
||||
var col = db.GetCollection<Jump>("Jump");
|
||||
|
||||
col.Insert(newJump);
|
||||
}
|
||||
_col.Insert(newJump);
|
||||
_dataProvider.Close();
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -59,5 +49,9 @@ namespace skydiveLogs_api.Data
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
private readonly LiteCollection<Jump> _col;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,32 +11,29 @@ namespace skydiveLogs_api.Data
|
||||
{
|
||||
public class JumpTypeRepository : IJumpTypeRepository
|
||||
{
|
||||
public JumpTypeRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
_col = _dataProvider.CollOfJumpType;
|
||||
}
|
||||
|
||||
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"))
|
||||
{
|
||||
var col = db.GetCollection<JumpType>("JumpType");
|
||||
|
||||
result = col.FindAll().ToList();
|
||||
}
|
||||
|
||||
return result;
|
||||
return results;
|
||||
}
|
||||
|
||||
public JumpType GetById(int id)
|
||||
{
|
||||
JumpType result;
|
||||
|
||||
using (var db = new LiteDatabase(@".\Data\MyData.db"))
|
||||
{
|
||||
var col = db.GetCollection<JumpType>("JumpType");
|
||||
|
||||
result = col.FindById(new BsonValue(id));
|
||||
}
|
||||
var result = _col.FindById(new BsonValue(id));
|
||||
_dataProvider.Close();
|
||||
|
||||
return result;
|
||||
}
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
private readonly LiteCollection<JumpType> _col;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user