From e0ddb8e34b8f5a034f3a686c66b9569afc9eb6fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Andr=C3=A9?= Date: Wed, 30 Oct 2019 16:36:26 +0100 Subject: [PATCH] Ajout de l'action d'ajout de saut. --- Back/skydiveLogs-api.Business/JumpService.cs | 5 ++-- .../Interface/IJumpRepository.cs | 6 ++-- Back/skydiveLogs-api.Data/JumpRepository.cs | 28 +++++++++++++++++++ Back/skydiveLogs-api/Data/Jump.json | 14 +--------- Back/skydiveLogs-api/DataContract/JumpReq.cs | 19 +++++++++++++ .../Properties/launchSettings.json | 2 +- 6 files changed, 55 insertions(+), 19 deletions(-) diff --git a/Back/skydiveLogs-api.Business/JumpService.cs b/Back/skydiveLogs-api.Business/JumpService.cs index 1c60531..a9fad38 100644 --- a/Back/skydiveLogs-api.Business/JumpService.cs +++ b/Back/skydiveLogs-api.Business/JumpService.cs @@ -1,10 +1,11 @@ using System; using System.Collections.Generic; -using System.Text; + using skydiveLogs_api.Business.Interface; using skydiveLogs_api.Model; using skydiveLogs_api.Data.Interface; + namespace skydiveLogs_api.Business { public class JumpService : IJumpService @@ -16,7 +17,7 @@ namespace skydiveLogs_api.Business public void AddNewJump(Jump jump) { - throw new NotImplementedException(); + _jumpRepository.AddJump(jump); } public void DeleteJumpById(int id) diff --git a/Back/skydiveLogs-api.Data/Interface/IJumpRepository.cs b/Back/skydiveLogs-api.Data/Interface/IJumpRepository.cs index 452b4da..c5c226a 100644 --- a/Back/skydiveLogs-api.Data/Interface/IJumpRepository.cs +++ b/Back/skydiveLogs-api.Data/Interface/IJumpRepository.cs @@ -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 GetAllJumps(); Jump GetJumpById(int id); + + bool AddJump(Jump newJump); } } diff --git a/Back/skydiveLogs-api.Data/JumpRepository.cs b/Back/skydiveLogs-api.Data/JumpRepository.cs index 1d6c3b9..f60255f 100644 --- a/Back/skydiveLogs-api.Data/JumpRepository.cs +++ b/Back/skydiveLogs-api.Data/JumpRepository.cs @@ -38,5 +38,33 @@ namespace skydiveLogs_api.Data return result; } + + public bool AddJump(Jump newJump) + { + var result = true; + List 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>(); + } + + newJump.Id = jumpList.Count() + 1; + jumpList.Add(newJump); + + string outputJson = JsonConvert.SerializeObject(jumpList); + File.WriteAllText(@"Data/Jump.json", outputJson); + } + catch + { + result = false; + } + + return result; + } } } diff --git a/Back/skydiveLogs-api/Data/Jump.json b/Back/skydiveLogs-api/Data/Jump.json index 52991fe..0e9436d 100644 --- a/Back/skydiveLogs-api/Data/Jump.json +++ b/Back/skydiveLogs-api/Data/Jump.json @@ -1,13 +1 @@ -[ - { - "id": 1, - "jumpTypeId" : 1, - "aircraftId" : 1, - "dropZoneId" : 1, - "gearId" : 1, - "exitAltitude" : "4000", - "deployAltitude" : "1500", - "withCutaway" : false, - "notes" : "" - } -] \ No newline at end of file +[{"Id":1,"JumpTypeId":1,"AircraftId":5,"DropZoneId":6,"GearId":8,"ExitAltitude":40001,"DeployAltitude":10002,"WithCutaway":true,"Notes":"","JumpDate":"0001-01-01T00:00:00"},{"Id":2,"JumpTypeId":1,"AircraftId":5,"DropZoneId":6,"GearId":8,"ExitAltitude":40001,"DeployAltitude":10002,"WithCutaway":true,"Notes":"","JumpDate":"0001-01-01T00:00:00"}] \ No newline at end of file diff --git a/Back/skydiveLogs-api/DataContract/JumpReq.cs b/Back/skydiveLogs-api/DataContract/JumpReq.cs index 63da3b8..2bc2da0 100644 --- a/Back/skydiveLogs-api/DataContract/JumpReq.cs +++ b/Back/skydiveLogs-api/DataContract/JumpReq.cs @@ -7,5 +7,24 @@ namespace skydiveLogs_api.DataContract { public class JumpReq { + public int Id { get; set; } + + public int JumpTypeId { get; set; } + + public int AircraftId { get; set; } + + public int DropZoneId { get; set; } + + public int GearId { get; set; } + + public int ExitAltitude { get; set; } + + public int DeployAltitude { get; set; } + + public bool WithCutaway { get; set; } + + public string Notes { get; set; } + + public DateTime JumpDate { get; set; } } } diff --git a/Back/skydiveLogs-api/Properties/launchSettings.json b/Back/skydiveLogs-api/Properties/launchSettings.json index 97c195e..ec5450c 100644 --- a/Back/skydiveLogs-api/Properties/launchSettings.json +++ b/Back/skydiveLogs-api/Properties/launchSettings.json @@ -3,7 +3,7 @@ "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:51376", + "applicationUrl": "http://localhost:5000", "sslPort": 0 } },