Add LiteDb in all repositories

This commit is contained in:
Sébastien André
2019-11-10 17:23:53 +01:00
parent cac3bbcf6d
commit 6d0c0f7a7f
12 changed files with 88 additions and 1175 deletions

View File

@@ -1,13 +1,12 @@
using skydiveLogs_api.Data.Interface;
using skydiveLogs_api.Model;
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using LiteDB;
using skydiveLogs_api.Data.Interface;
using skydiveLogs_api.Model;
namespace skydiveLogs_api.Data
{
public class AircraftRepository : IAircraftRepository
@@ -16,11 +15,11 @@ namespace skydiveLogs_api.Data
{
IEnumerable<Aircraft> result = new List<Aircraft>();
using (StreamReader file = File.OpenText(@"Data/Aircraft.json"))
using (JsonTextReader reader = new JsonTextReader(file))
using (var db = new LiteDatabase(@".\Data\MyData.db"))
{
var jsonResult = (JArray)JToken.ReadFrom(reader);
result = jsonResult.ToObject<IEnumerable<Aircraft>>();
var col = db.GetCollection<Aircraft>("Aircraft");
result = col.FindAll().ToList();
}
return result;
@@ -30,12 +29,11 @@ namespace skydiveLogs_api.Data
{
Aircraft result;
using (StreamReader file = File.OpenText(@"Data/Aircraft.json"))
using (JsonTextReader reader = new JsonTextReader(file))
using (var db = new LiteDatabase(@".\Data\MyData.db"))
{
var jsonResult = (JArray)JToken.ReadFrom(reader);
var tmp = jsonResult.ToObject<IEnumerable<Aircraft>>();
result = tmp.SingleOrDefault(t => t.Id == id);
var col = db.GetCollection<Aircraft>("Aircraft");
result = col.FindById(new BsonValue(id));
}
return result;