oop_NFS_Andreas/Plattform/Plattform/PlattformService.svc.cs

82 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Plattform.DB;
using Plattform.Models;
using Plattform.AirlineService;
namespace Plattform
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change
// the class name "PlattformService" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please
// select PlattformService.svc or PlattformService.svc.cs at the Solution
// Explorer and start debugging.
public class PlattformService : IPlattformService
{
SpecialOfferDB db = new SpecialOfferDB();
AirlineServiceClient client = new AirlineServiceClient();
public List<SpecialOffer> GetSpecialOffers()
{
try
{
return db.GetAllSpecialOffers();
}
catch(Exception e)
{
System.Diagnostics.Trace.WriteLine(e);
return new List<SpecialOffer>();
}
}
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;
}
}
}
}