From 91b31afd0db8851a170043750114cce0a8d0914e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Andr=C3=A9?= Date: Wed, 4 Dec 2019 13:51:28 +0100 Subject: [PATCH] Implement the function "Add a aircraft" --- .../skydiveLogs-api.Business/AircraftService.cs | 4 ++-- .../skydiveLogs-api.Business/DropZoneService.cs | 4 ---- Back/skydiveLogs-api.Data/AircraftRepository.cs | 17 +++++++++++++++++ .../Interface/IAircraftRepository.cs | 1 + .../skydiveLogs-api/DataContract/AircraftReq.cs | 10 ++++------ 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Back/skydiveLogs-api.Business/AircraftService.cs b/Back/skydiveLogs-api.Business/AircraftService.cs index fd7e205..76ab374 100644 --- a/Back/skydiveLogs-api.Business/AircraftService.cs +++ b/Back/skydiveLogs-api.Business/AircraftService.cs @@ -15,9 +15,9 @@ namespace skydiveLogs_api.Business _aircraftRepository = aircraftRepository; } - public void AddNewAircraft(Aircraft aircraft) + public void AddNewAircraft(Aircraft newAircraft) { - throw new NotImplementedException(); + _aircraftRepository.AddAircraft(newAircraft); } public void DeleteAircraftById(int id) diff --git a/Back/skydiveLogs-api.Business/DropZoneService.cs b/Back/skydiveLogs-api.Business/DropZoneService.cs index 0543cf1..37b0136 100644 --- a/Back/skydiveLogs-api.Business/DropZoneService.cs +++ b/Back/skydiveLogs-api.Business/DropZoneService.cs @@ -39,10 +39,6 @@ namespace skydiveLogs_api.Business { dropZone.Id = id; - //dropZone.Address = dropZone.Address ?? string.Empty; - //dropZone.Website = dropZone.Address ?? string.Empty; - //dropZone.Email = dropZone.Address ?? string.Empty; - return _dropZoneRepository.Update(dropZone); } diff --git a/Back/skydiveLogs-api.Data/AircraftRepository.cs b/Back/skydiveLogs-api.Data/AircraftRepository.cs index d0c5692..47f0ca0 100644 --- a/Back/skydiveLogs-api.Data/AircraftRepository.cs +++ b/Back/skydiveLogs-api.Data/AircraftRepository.cs @@ -32,6 +32,23 @@ namespace skydiveLogs_api.Data return _col.Update(aircraft); } + public bool AddAircraft(Aircraft newAircraft) + { + var result = true; + + try + { + _col.Insert(newAircraft); + } + catch + { + result = false; + } + + return result; + } + + private readonly IDataProvider _dataProvider; private readonly LiteCollection _col; diff --git a/Back/skydiveLogs-api.Data/Interface/IAircraftRepository.cs b/Back/skydiveLogs-api.Data/Interface/IAircraftRepository.cs index 4e0fab6..6a04814 100644 --- a/Back/skydiveLogs-api.Data/Interface/IAircraftRepository.cs +++ b/Back/skydiveLogs-api.Data/Interface/IAircraftRepository.cs @@ -5,5 +5,6 @@ namespace skydiveLogs_api.Data.Interface { public interface IAircraftRepository : IRepository { + bool AddAircraft(Aircraft newAircraft); } } diff --git a/Back/skydiveLogs-api/DataContract/AircraftReq.cs b/Back/skydiveLogs-api/DataContract/AircraftReq.cs index f205214..118c467 100644 --- a/Back/skydiveLogs-api/DataContract/AircraftReq.cs +++ b/Back/skydiveLogs-api/DataContract/AircraftReq.cs @@ -1,11 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace skydiveLogs_api.DataContract +namespace skydiveLogs_api.DataContract { public class AircraftReq { + public int Id { get; set; } + + public string Name { get; set; } } }