45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
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>>();
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|