Add LiteDb in all repositories
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using LiteDB;
|
||||
|
||||
using skydiveLogs_api.Data.Interface;
|
||||
using skydiveLogs_api.Model;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Data
|
||||
{
|
||||
@@ -14,11 +15,11 @@ namespace skydiveLogs_api.Data
|
||||
{
|
||||
IEnumerable<Jump> result = new List<Jump>();
|
||||
|
||||
using (StreamReader file = File.OpenText(@"Data/Jump.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<Jump>>();
|
||||
var col = db.GetCollection<Jump>("Jump");
|
||||
|
||||
result = col.FindAll().ToList();
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -28,12 +29,11 @@ namespace skydiveLogs_api.Data
|
||||
{
|
||||
Jump result;
|
||||
|
||||
using (StreamReader file = File.OpenText(@"Data/Jump.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<Jump>>();
|
||||
result = tmp.SingleOrDefault(t => t.Id == id);
|
||||
var col = db.GetCollection<Jump>("Jump");
|
||||
|
||||
result = col.FindById(new BsonValue(id));
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -42,22 +42,15 @@ namespace skydiveLogs_api.Data
|
||||
public bool AddJump(Jump newJump)
|
||||
{
|
||||
var result = true;
|
||||
List<Jump> jumpList;
|
||||
|
||||
try
|
||||
{
|
||||
using (StreamReader file = File.OpenText(@"Data/Jump.json"))
|
||||
using (JsonTextReader reader = new JsonTextReader(file))
|
||||
using (var db = new LiteDatabase(@".\Data\MyData.db"))
|
||||
{
|
||||
var jsonResult = (JArray)JToken.ReadFrom(reader);
|
||||
jumpList = jsonResult.ToObject<List<Jump>>();
|
||||
var col = db.GetCollection<Jump>("Jump");
|
||||
|
||||
col.Insert(newJump);
|
||||
}
|
||||
|
||||
newJump.Id = jumpList.Count() + 1;
|
||||
jumpList.Add(newJump);
|
||||
|
||||
string outputJson = JsonConvert.SerializeObject(jumpList);
|
||||
File.WriteAllText(@"Data/Jump.json", outputJson);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user