57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
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
|
|
{
|
|
public IEnumerable<DropZone> GetAllDzs()
|
|
{
|
|
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;
|
|
}
|
|
|
|
public DropZone GetDzById(int id)
|
|
{
|
|
DropZone result;
|
|
|
|
using (StreamReader file = File.OpenText(@"Data/DropZone.json"))
|
|
using (JsonTextReader reader = new JsonTextReader(file))
|
|
{
|
|
var jsonResult = (JArray)JToken.ReadFrom(reader);
|
|
var tmp = jsonResult.ToObject<IEnumerable<DropZone>>();
|
|
result = tmp.SingleOrDefault(t => t.Id == id);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|