Add the method "Get*ById" in the stack Business

This commit is contained in:
Sébastien André
2019-09-30 15:16:34 +02:00
parent ed3f7c42c5
commit c6c2777c22
16 changed files with 74 additions and 12 deletions

View File

@@ -6,6 +6,7 @@ using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Linq;
namespace skydiveLogs_api.Data
{
@@ -24,5 +25,20 @@ namespace skydiveLogs_api.Data
return result;
}
public Aircraft GetAircraftById(int id)
{
Aircraft result;
using (StreamReader file = File.OpenText(@"Data/Aircraft.json"))
using (JsonTextReader reader = new JsonTextReader(file))
{
var jsonResult = (JArray)JToken.ReadFrom(reader);
var tmp = jsonResult.ToObject<IEnumerable<Aircraft>>();
result = tmp.SingleOrDefault(t => t.Id == id);
}
return result;
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@@ -24,5 +25,20 @@ namespace skydiveLogs_api.Data
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;
}
}
}

View File

@@ -8,5 +8,6 @@ namespace skydiveLogs_api.Data.Interface
public interface IAircraftRepository
{
IEnumerable<Aircraft> GetAllAircrafts();
Aircraft GetAircraftById(int id);
}
}

View File

@@ -8,5 +8,7 @@ namespace skydiveLogs_api.Data.Interface
public interface IDropZoneRepository
{
IEnumerable<DropZone> GetAllDzs();
DropZone GetDzById(int id);
}
}

View File

@@ -8,5 +8,6 @@ namespace skydiveLogs_api.Data.Interface
public interface IJumpRepository
{
IEnumerable<Jump> GetAllJumps();
Jump GetJumpById(int id);
}
}

View File

@@ -8,5 +8,6 @@ namespace skydiveLogs_api.Data.Interface
public interface IJumpTypeRepository
{
IEnumerable<JumpType> GetAllJumpTypes();
JumpType GetJumpTypeById(int id);
}
}

View File

@@ -1,11 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
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
{
@@ -24,5 +23,20 @@ namespace skydiveLogs_api.Data
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;
}
}
}

View File

@@ -6,6 +6,7 @@ using skydiveLogs_api.Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Linq;
namespace skydiveLogs_api.Data
{
@@ -24,5 +25,20 @@ namespace skydiveLogs_api.Data
return result;
}
public JumpType GetJumpTypeById(int id)
{
JumpType result;
using (StreamReader file = File.OpenText(@"Data/JumpType.json"))
using (JsonTextReader reader = new JsonTextReader(file))
{
var jsonResult = (JArray)JToken.ReadFrom(reader);
var tmp = jsonResult.ToObject<IEnumerable<JumpType>>();
result = tmp.SingleOrDefault(t => t.Id == id);
}
return result;
}
}
}