From 41b6c58cd059bd4cae3c1f0a182144e936e0d51c Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Tue, 28 Aug 2018 21:52:36 +0200 Subject: [PATCH] add the Plattform service --- Plattform/Plattform/IPlattformService.cs | 10 +++- Plattform/Plattform/PlattformService.svc.cs | 62 ++++++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/Plattform/Plattform/IPlattformService.cs b/Plattform/Plattform/IPlattformService.cs index b7856d5..7ad5200 100644 --- a/Plattform/Plattform/IPlattformService.cs +++ b/Plattform/Plattform/IPlattformService.cs @@ -4,6 +4,8 @@ using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; +using Plattform.DB; +using Plattform.Models; namespace Plattform { @@ -12,6 +14,12 @@ namespace Plattform public interface IPlattformService { [OperationContract] - void DoWork(); + List GetSpecialOffers(); + [OperationContract] + bool ReserveSpecialOffer(SpecialOffer offer); + [OperationContract] + bool BookSpecialOffer(SpecialOffer offer); + [OperationContract] + bool CancelSpecialOffer(SpecialOffer offer); } } diff --git a/Plattform/Plattform/PlattformService.svc.cs b/Plattform/Plattform/PlattformService.svc.cs index ceec896..7580650 100644 --- a/Plattform/Plattform/PlattformService.svc.cs +++ b/Plattform/Plattform/PlattformService.svc.cs @@ -4,6 +4,9 @@ using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; +using Plattform.DB; +using Plattform.Models; +using Plattform.AirlineService; namespace Plattform { @@ -14,8 +17,65 @@ namespace Plattform // Explorer and start debugging. public class PlattformService : IPlattformService { - public void DoWork() + SpecialOfferDB db = new SpecialOfferDB(); + AirlineServiceClient client = new AirlineServiceClient(); + public List GetSpecialOffers() { + try + { + return db.GetAllSpecialOffers(); + } + catch(Exception e) + { + System.Diagnostics.Trace.WriteLine(e); + return new List(); + } + } + public bool ReserveSpecialOffer(SpecialOffer offer) + { + try + { + client.BookFlight(offer.FlightTo, offer.Room.RoomType.Capacity); + client.BookFlight(offer.FlightFrom, offer.Room.RoomType.Capacity); + offer.Reserverd = true; + db.UpdateSpecialOffer(offer); + return true; + } + catch(Exception e) + { + System.Diagnostics.Trace.WriteLine(e); + return false; + } + } + public bool BookSpecialOffer(SpecialOffer offer) + { + try + { + offer.Booked = true; + db.UpdateSpecialOffer(offer); + return true; + } + catch(Exception e) + { + System.Diagnostics.Trace.WriteLine(e); + return false; + } + } + public bool CancelSpecialOffer(SpecialOffer offer) + { + try + { + client.CancelFlight(offer.FlightTo, offer.Room.RoomType.Capacity); + client.CancelFlight(offer.FlightFrom, offer.Room.RoomType.Capacity); + offer.Reserverd = false; + db.UpdateSpecialOffer(offer); + return true; + } + catch(Exception e) + { + System.Diagnostics.Trace.WriteLine(e); + return false; + } } } }