diff --git a/Plattform/Plattform/DB/AirportDB.cs b/Plattform/Plattform/DB/AirportDB.cs new file mode 100644 index 0000000..a866e49 --- /dev/null +++ b/Plattform/Plattform/DB/AirportDB.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Plattform.Models; + +namespace Plattform.DB +{ + public class AirportDB + { + public ICollection GetAllAirports() + { + using (Context ctx = new Context()) + { + return ctx.Airports.ToList(); + } + } + public bool CreateAirport(Airport airport) + { + try + { + using (Context ctx = new Context()) + { + ctx.Airports.Add(airport); + ctx.SaveChanges(); + } + return true; + } + catch (Exception e) + { + System.Diagnostics.Trace.WriteLine(e); + return false; + } + } + + public bool UpdateAirport(Airport airport) + { + try + { + using (Context ctx = new Context()) + { + ctx.Airports.Attach(airport); + ctx.Entry(airport).State = System.Data.Entity.EntityState.Modified; + ctx.SaveChanges(); + } + return true; + } + catch (Exception e) + { + System.Diagnostics.Trace.WriteLine(e); + return false; + } + + } + public bool DeleteAirport(Airport airport) + { + try + { + using (Context ctx = new Context()) + { + ctx.Airports.Attach(airport); + ctx.Airports.Remove(airport); + ctx.SaveChanges(); + } + return true; + } + catch (Exception e) + { + System.Diagnostics.Trace.WriteLine(e); + return false; + } + } + } +} diff --git a/Plattform/Plattform/DB/CityDB.cs b/Plattform/Plattform/DB/CityDB.cs index 126d1ef..9288227 100644 --- a/Plattform/Plattform/DB/CityDB.cs +++ b/Plattform/Plattform/DB/CityDB.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using Plattform.Models; -using Plattform.AirlineService; +using Plattform; namespace Plattform.DB { diff --git a/Plattform/Plattform/DB/Context.cs b/Plattform/Plattform/DB/Context.cs index 057de8b..77df345 100644 --- a/Plattform/Plattform/DB/Context.cs +++ b/Plattform/Plattform/DB/Context.cs @@ -15,6 +15,10 @@ namespace Plattform.DB public DbSet Rooms { get; set; } public DbSet RoomTypes { get; set; } public DbSet Availabilities { get; set; } + public DbSet Airports { get; set; } + public DbSet Genders { get; set; } + public DbSet Salutations { get; set; } + public DbSet SpecialOffers { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { @@ -45,17 +49,12 @@ namespace Plattform.DB .Property(f => f.Duration) .IsRequired(); - modelBuilder.Entity() - .Property(f => f.FromCityShortName) - .IsRequired(); - modelBuilder.Entity() .Property(f => f.StartTime) .IsRequired(); - modelBuilder.Entity() - .Property(f => f.ToCityShortName) - .IsRequired(); + modelBuilder.Entity() + .HasKey(f => f.ShortName); } } } \ No newline at end of file diff --git a/Plattform/Plattform/DB/GenderDB.cs b/Plattform/Plattform/DB/GenderDB.cs new file mode 100644 index 0000000..2c25547 --- /dev/null +++ b/Plattform/Plattform/DB/GenderDB.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Plattform.Models; + +namespace Plattform.DB +{ + public class GenderDB + { + public ICollection GetAllGenders() + { + using (Context ctx = new Context()) + { + return ctx.Genders.ToList(); + } + } + public bool CreateGender(Gender gender) + { + try + { + using (Context ctx = new Context()) + { + ctx.Genders.Add(gender); + ctx.SaveChanges(); + } + return true; + } + catch (Exception e) + { + System.Diagnostics.Trace.WriteLine(e); + return false; + } + } + + public bool UpdateGender(Gender gender) + { + try + { + using (Context ctx = new Context()) + { + ctx.Genders.Attach(gender); + ctx.Entry(gender).State = System.Data.Entity.EntityState.Modified; + ctx.SaveChanges(); + } + return true; + } + catch (Exception e) + { + System.Diagnostics.Trace.WriteLine(e); + return false; + } + + } + public bool DeleteGender(Gender gender) + { + try + { + using (Context ctx = new Context()) + { + ctx.Genders.Attach(gender); + ctx.Genders.Remove(gender); + ctx.SaveChanges(); + } + return true; + } + catch (Exception e) + { + System.Diagnostics.Trace.WriteLine(e); + return false; + } + } + } +} diff --git a/Plattform/Plattform/DB/SalutationDB.cs b/Plattform/Plattform/DB/SalutationDB.cs new file mode 100644 index 0000000..58358c7 --- /dev/null +++ b/Plattform/Plattform/DB/SalutationDB.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Plattform.Models; + +namespace Plattform.DB +{ + public class SalutationDB + { + public ICollection GetAllSalutations() + { + using (Context ctx = new Context()) + { + return ctx.Salutations.ToList(); + } + } + public bool CreateSalutation(Salutation salutation) + { + try + { + using (Context ctx = new Context()) + { + ctx.Salutations.Add(salutation); + ctx.SaveChanges(); + } + return true; + } + catch (Exception e) + { + System.Diagnostics.Trace.WriteLine(e); + return false; + } + } + + public bool UpdateSalutation(Salutation salutation) + { + try + { + using (Context ctx = new Context()) + { + ctx.Salutations.Attach(salutation); + ctx.Entry(salutation).State = System.Data.Entity.EntityState.Modified; + ctx.SaveChanges(); + } + return true; + } + catch (Exception e) + { + System.Diagnostics.Trace.WriteLine(e); + return false; + } + + } + public bool DeleteSalutation(Salutation salutation) + { + try + { + using (Context ctx = new Context()) + { + ctx.Salutations.Attach(salutation); + ctx.Salutations.Remove(salutation); + ctx.SaveChanges(); + } + return true; + } + catch (Exception e) + { + System.Diagnostics.Trace.WriteLine(e); + return false; + } + } + } +} diff --git a/Plattform/Plattform/DB/SpecialOfferDB.cs b/Plattform/Plattform/DB/SpecialOfferDB.cs new file mode 100644 index 0000000..a132fda --- /dev/null +++ b/Plattform/Plattform/DB/SpecialOfferDB.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Plattform.Models; + +namespace Plattform.DB +{ + public class SpecialOfferDB + { + public ICollection GetAllSpecialOffers() + { + using (Context ctx = new Context()) + { + return ctx.SpecialOffers.ToList(); + } + } + public bool CreateSpecialOffer(SpecialOffer specialOffer) + { + try + { + using (Context ctx = new Context()) + { + ctx.SpecialOffers.Add(specialOffer); + ctx.SaveChanges(); + } + return true; + } + catch (Exception e) + { + System.Diagnostics.Trace.WriteLine(e); + return false; + } + } + + public bool UpdateSpecialOffer(SpecialOffer specialOffer) + { + try + { + using (Context ctx = new Context()) + { + ctx.SpecialOffers.Attach(specialOffer); + ctx.Entry(specialOffer).State = System.Data.Entity.EntityState.Modified; + ctx.SaveChanges(); + } + return true; + } + catch (Exception e) + { + System.Diagnostics.Trace.WriteLine(e); + return false; + } + + } + public bool DeleteSpecialOffer(SpecialOffer specialOffer) + { + try + { + using (Context ctx = new Context()) + { + ctx.SpecialOffers.Attach(specialOffer); + ctx.SpecialOffers.Remove(specialOffer); + ctx.SaveChanges(); + } + return true; + } + catch (Exception e) + { + System.Diagnostics.Trace.WriteLine(e); + return false; + } + } + } +} diff --git a/Plattform/Plattform/Helper/GenerateData.cs b/Plattform/Plattform/Helper/GenerateData.cs index 86fa81d..f4b6607 100644 --- a/Plattform/Plattform/Helper/GenerateData.cs +++ b/Plattform/Plattform/Helper/GenerateData.cs @@ -21,7 +21,7 @@ namespace Plattform.Helper { foreach (var item in ListRoomTypes) { - RoomTypes.Add(new RoomType(item)); + RoomTypes.Add(new RoomType(item, 2, "blubl" )); } return RoomTypes; } @@ -29,7 +29,7 @@ namespace Plattform.Helper { foreach (var item in ListCities) { - Cities.Add(new City(item, 3300, "xtz")); + Cities.Add(new City(item, 3300)); } return Cities; } diff --git a/Plattform/Plattform/Models/Airline.cs b/Plattform/Plattform/Models/Airline.cs index 21b481f..a466f47 100644 --- a/Plattform/Plattform/Models/Airline.cs +++ b/Plattform/Plattform/Models/Airline.cs @@ -14,6 +14,8 @@ namespace Plattform.Models public int AirlineID { get; set; } [DataMember] public string Name { get; set; } + + public Airline(){ } public Airline(AirlineService.Airline airline) { this.Name = airline.Name; diff --git a/Plattform/Plattform/Models/Airport.cs b/Plattform/Plattform/Models/Airport.cs index 4131e4b..ec8a391 100644 --- a/Plattform/Plattform/Models/Airport.cs +++ b/Plattform/Plattform/Models/Airport.cs @@ -1,8 +1,11 @@ -using System.Runtime.Serialization; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; using System.Runtime.Serialization; using Plattform; -namespace Plattfrom.Models +namespace Plattform.Models { [DataContract] public class Airport @@ -13,12 +16,18 @@ namespace Plattfrom.Models public string Name { get; set; } [DataMember] public virtual City City { get; set; } - public Airport(){ } + + public Airport() { } public Airport(AirlineService.Airport airport) { + City city = new City + { + Name = airport.City.Name, + ZipCode = airport.City.ZipCode, + }; this.Name = airport.Name; + this.City = city; this.ShortName = airport.ShortName; - this.City = airport.City; } } } diff --git a/Plattform/Plattform/Models/Availability.cs b/Plattform/Plattform/Models/Availability.cs index cec46a4..029356b 100644 --- a/Plattform/Plattform/Models/Availability.cs +++ b/Plattform/Plattform/Models/Availability.cs @@ -13,10 +13,5 @@ namespace Plattform.Models public DateTime From { get; set; } [DataMember] public DateTime To { get; set; } - [DataMember] - bool Reserved { get; set; } - [DataMember] - bool Booked { get; set; } - public ICollection Rooms { get; set; } } } diff --git a/Plattform/Plattform/Models/City.cs b/Plattform/Plattform/Models/City.cs index ededc14..9d0d867 100644 --- a/Plattform/Plattform/Models/City.cs +++ b/Plattform/Plattform/Models/City.cs @@ -11,14 +11,11 @@ namespace Plattform.Models public string Name { get; set; } [DataMember] public int ZipCode { get; set; } - [DataMember] - public string ShortName { get; set; } public City() { } - public City(string name, int zipCode, string shortName) + public City(string name, int zipCode) { this.Name = name; this.ZipCode = zipCode; - this.ShortName = shortName; } } } diff --git a/Plattform/Plattform/Models/Flight.cs b/Plattform/Plattform/Models/Flight.cs index 75db37f..3be235e 100644 --- a/Plattform/Plattform/Models/Flight.cs +++ b/Plattform/Plattform/Models/Flight.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.Serialization; +using Plattform; namespace Plattform.Models { @@ -21,14 +22,16 @@ namespace Plattform.Models [DataMember] public virtual Airport Destination { get; set; } - public Flight (AirlineService.Flight flight) + public Flight(AirlineService.Flight flight) { + Airport origin = new Airport(flight.Origin); + Airport destination = new Airport(flight.Destination); this.Airline = new Airline(flight.Airline); this.Name = flight.Name; this.StartTime = flight.StartTime; this.Duration = flight.Duration; - this.FromCityShortName = flight.FromCityShortName; - this.ToCityShortName = flight.ToCityShortName; + this.Origin = origin; + this.Destination = destination; } } } diff --git a/Plattform/Plattform/Models/Room.cs b/Plattform/Plattform/Models/Room.cs index f91910f..7b4742e 100644 --- a/Plattform/Plattform/Models/Room.cs +++ b/Plattform/Plattform/Models/Room.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Runtime.Serialization; namespace Plattform.Models @@ -13,6 +14,18 @@ namespace Plattform.Models [DataMember] public Hotel Hotel { get; set; } [DataMember] - public ICollection Availability { get; set; } + public DateTime FreeFrom { get; set; } + [DataMember] + public DateTime FreeUntil { get; set; } + + public Room() { } + public Room(RoomType roomType, Hotel hotel, DateTime freeFrom, + DateTime freeUntil) + { + this.RoomType = roomType; + this.Hotel = hotel; + this.FreeFrom = freeFrom; + this.FreeUntil = freeUntil; + } } } diff --git a/Plattform/Plattform/Models/RoomAvailability.cs b/Plattform/Plattform/Models/RoomAvailability.cs deleted file mode 100644 index 412350c..0000000 --- a/Plattform/Plattform/Models/RoomAvailability.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Runtime.Serialization; - -namespace Plattform.Models -{ - [DataContract] - public class RoomAvailability - { - [DataMember] - public Room Room; - [DataMember] - public Availability Availability; - [DataMember] - public Customer Customer; - } -} diff --git a/Plattform/Plattform/Models/RoomType.cs b/Plattform/Plattform/Models/RoomType.cs index 733b683..69aa9e3 100644 --- a/Plattform/Plattform/Models/RoomType.cs +++ b/Plattform/Plattform/Models/RoomType.cs @@ -9,10 +9,17 @@ namespace Plattform.Models public int RoomTypeID { get; set; } [DataMember] public string Name { get; set; } + [DataMember] + public int Capacity { get; set; } + [DataMember] + public string Inventory { get; set; } + public RoomType() { } - public RoomType(string name) + public RoomType(string name, int capacity, string inventory) { this.Name = name; + this.Capacity = capacity; + this.Inventory = inventory; } } } diff --git a/Plattform/Plattform/Models/SpecialOffer.cs b/Plattform/Plattform/Models/SpecialOffer.cs new file mode 100644 index 0000000..bb74208 --- /dev/null +++ b/Plattform/Plattform/Models/SpecialOffer.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace Plattform.Models +{ + [DataContract] + public class SpecialOffer + { + [DataMember] + public int SpecialOfferID { get; set; } + [DataMember] + public virtual Flight Flight { get; set; } + [DataMember] + public virtual Person Customer { get; set; } + [DataMember] + public virtual Room Room { get; set; } + [DataMember] + public float Price { get; set; } + [DataMember] + public bool Reserverd { get; set; } + [DataMember] + public DateTime ReservationDate { get; set; } + [DataMember] + public bool Booked { get; set; } + + public SpecialOffer() { } + public SpecialOffer(Flight flight, Room room, float price) + { + this.Flight = flight; + this.Room = room; + this.Price = price; + this.Reserverd = false; + this.Booked = false; + } + } +} diff --git a/Plattform/Plattform/Plattform.csproj b/Plattform/Plattform/Plattform.csproj index 6f2839c..658b4ab 100644 --- a/Plattform/Plattform/Plattform.csproj +++ b/Plattform/Plattform/Plattform.csproj @@ -118,14 +118,18 @@ True Reference.svcmap + + + + Global.asax @@ -141,13 +145,17 @@ + + + - + + PlattformService.svc