Ajout de l'action d'ajout de saut.
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
namespace skydiveLogs_api.Data.Interface
|
||||
@@ -10,5 +8,7 @@ namespace skydiveLogs_api.Data.Interface
|
||||
IEnumerable<Jump> GetAllJumps();
|
||||
|
||||
Jump GetJumpById(int id);
|
||||
|
||||
bool AddJump(Jump newJump);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,5 +38,33 @@ namespace skydiveLogs_api.Data
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool AddJump(Jump newJump)
|
||||
{
|
||||
var result = true;
|
||||
List<Jump> jumpList;
|
||||
|
||||
try
|
||||
{
|
||||
using (StreamReader file = File.OpenText(@"Data/Jump.json"))
|
||||
using (JsonTextReader reader = new JsonTextReader(file))
|
||||
{
|
||||
var jsonResult = (JArray)JToken.ReadFrom(reader);
|
||||
jumpList = jsonResult.ToObject<List<Jump>>();
|
||||
}
|
||||
|
||||
newJump.Id = jumpList.Count() + 1;
|
||||
jumpList.Add(newJump);
|
||||
|
||||
string outputJson = JsonConvert.SerializeObject(jumpList);
|
||||
File.WriteAllText(@"Data/Jump.json", outputJson);
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user