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,12 +1,12 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using LiteDB;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using skydiveLogs_api.Data.Interface;
using skydiveLogs_api.Model;
namespace skydiveLogs_api.Data
{
public class DropZoneRepository : IDropZoneRepository
@@ -15,24 +15,11 @@ namespace skydiveLogs_api.Data
{
IEnumerable<DropZone> result = new List<DropZone>();
//using (StreamReader file = File.OpenText(@"Data/DropZone.json"))
//using (JsonTextReader reader = new JsonTextReader(file))
//{
// var jsonResult = (JArray)JToken.ReadFrom(reader);
// result = jsonResult.ToObject<IEnumerable<DropZone>>();
//}
using (var db = new LiteDatabase(@".\Data\MyData.db"))
{
// Get a collection (or create, if doesn't exist)
var col = db.GetCollection<DropZone>("DropZone");
result = col.FindAll().ToList();
//foreach (var item in result)
//{
// item.Id = 0;
// col.Insert(item);
//}
}
return result;
@@ -42,12 +29,11 @@ namespace skydiveLogs_api.Data
{
DropZone result;
using (StreamReader file = File.OpenText(@"Data/DropZone.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<DropZone>>();
result = tmp.SingleOrDefault(t => t.Id == id);
var col = db.GetCollection<DropZone>("DropZone");
result = col.FindById(new BsonValue(id));
}
return result;