Ajout de l'action d'ajout de saut.

This commit is contained in:
Sébastien André
2019-10-30 16:36:26 +01:00
parent 5c7eaa61c8
commit e0ddb8e34b
6 changed files with 55 additions and 19 deletions

View File

@@ -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);
}
}

View File

@@ -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;
}
}
}