Implementation of repositories and return infos

This commit is contained in:
Sébastien André
2019-09-26 15:31:17 +02:00
parent 4d6787af20
commit ed3f7c42c5
34 changed files with 1382 additions and 8 deletions

View File

@@ -1,11 +1,28 @@
using skydiveLogs_api.Data.Interface;
using skydiveLogs_api.Model;
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
namespace skydiveLogs_api.Data
{
public class AircraftRepository : IAircraftRepository
{
public IEnumerable<Aircraft> GetAllAircrafts()
{
IEnumerable<Aircraft> result = new List<Aircraft>();
using (StreamReader file = File.OpenText(@"Data/Aircraft.json"))
using (JsonTextReader reader = new JsonTextReader(file))
{
var jsonResult = (JArray)JToken.ReadFrom(reader);
result = jsonResult.ToObject<IEnumerable<Aircraft>>();
}
return result;
}
}
}

View File

@@ -1,11 +1,28 @@
using System;
using System.Collections.Generic;
using System.IO;
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;
}
}
}

View File

@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using skydiveLogs_api.Model;
namespace skydiveLogs_api.Data.Interface
{
public interface IAircraftRepository
{
IEnumerable<Aircraft> GetAllAircrafts();
}
}

View File

@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using skydiveLogs_api.Model;
namespace skydiveLogs_api.Data.Interface
{
public interface IDropZoneRepository
{
IEnumerable<DropZone> GetAllDzs();
}
}

View File

@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using skydiveLogs_api.Model;
namespace skydiveLogs_api.Data.Interface
{
public interface IJumpRepository
{
IEnumerable<Jump> GetAllJumps();
}
}

View File

@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using skydiveLogs_api.Model;
namespace skydiveLogs_api.Data.Interface
{
public interface IJumpTypeRepository
{
IEnumerable<JumpType> GetAllJumpTypes();
}
}

View File

@@ -2,10 +2,27 @@
using System.Collections.Generic;
using System.Text;
using skydiveLogs_api.Data.Interface;
using skydiveLogs_api.Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
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;
}
}
}

View File

@@ -2,10 +2,27 @@
using System.Collections.Generic;
using System.Text;
using skydiveLogs_api.Data.Interface;
using skydiveLogs_api.Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
namespace skydiveLogs_api.Data
{
public class JumpTypeRepository : IJumpTypeRepository
{
public IEnumerable<JumpType> GetAllJumpTypes()
{
IEnumerable<JumpType> result = new List<JumpType>();
using (StreamReader file = File.OpenText(@"Data/JumpType.json"))
using (JsonTextReader reader = new JsonTextReader(file))
{
var jsonResult = (JArray)JToken.ReadFrom(reader);
result = jsonResult.ToObject<IEnumerable<JumpType>>();
}
return result;
}
}
}

View File

@@ -31,6 +31,10 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\skydiveLogs-api.Model\skydiveLogs-api.Model.csproj" />
</ItemGroup>