Update the repositories to use the new interface
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user