43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
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
|
|
{
|
|
public class JumpRepository : IJumpRepository
|
|
{
|
|
public IEnumerable<Jump> GetAllJumps()
|
|
{
|
|
IEnumerable<Jump> result = new List<Jump>();
|
|
|
|
using (StreamReader file = File.OpenText(@"Data/Jump.json"))
|
|
using (JsonTextReader reader = new JsonTextReader(file))
|
|
{
|
|
var jsonResult = (JArray)JToken.ReadFrom(reader);
|
|
result = jsonResult.ToObject<IEnumerable<Jump>>();
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public Jump GetJumpById(int id)
|
|
{
|
|
Jump result;
|
|
|
|
using (StreamReader file = File.OpenText(@"Data/Jump.json"))
|
|
using (JsonTextReader reader = new JsonTextReader(file))
|
|
{
|
|
var jsonResult = (JArray)JToken.ReadFrom(reader);
|
|
var tmp = jsonResult.ToObject<IEnumerable<Jump>>();
|
|
result = tmp.SingleOrDefault(t => t.Id == id);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|