diff --git a/SeatsioDotNet.Test/Events/CreateEventTest.cs b/SeatsioDotNet.Test/Events/CreateEventTest.cs index cfcafb6..2f6637e 100644 --- a/SeatsioDotNet.Test/Events/CreateEventTest.cs +++ b/SeatsioDotNet.Test/Events/CreateEventTest.cs @@ -123,5 +123,16 @@ public void ChannelsCanBePassedIn() Assert.Equivalent(channels, evnt.Channels); } + + [Fact] + public void ForSaleConfigCanBePassedIn() + { + var chartKey = CreateTestChart(); + var forSaleConfig = new ForSaleConfig().WithForSale(false).WithObjects(new []{"A-1"}).WithAreaPlaces(new(){{"GA1", 5}}).WithCategories(new []{"Cat1"}); + + var evnt = Client.Events.Create(chartKey, new CreateEventParams().WithForSaleConfig(forSaleConfig)); + + Assert.Equivalent(forSaleConfig, evnt.ForSaleConfig); + } } } \ No newline at end of file diff --git a/SeatsioDotNet.Test/Events/CreateEventsTest.cs b/SeatsioDotNet.Test/Events/CreateEventsTest.cs index 3bb22f3..019b42e 100644 --- a/SeatsioDotNet.Test/Events/CreateEventsTest.cs +++ b/SeatsioDotNet.Test/Events/CreateEventsTest.cs @@ -175,5 +175,22 @@ public void ChannelsCanBePassedIn() Assert.Equivalent(channels, events[0].Channels); } + + [Fact] + public void ForSaleConfigCanBePassedIn() + { + var chartKey = CreateTestChart(); + var forSaleConfig1 = new ForSaleConfig().WithForSale(false).WithObjects(new []{"A-1"}).WithAreaPlaces(new(){{"GA1", 3}}).WithCategories(new []{"Cat1"}); + var forSaleConfig2 = new ForSaleConfig().WithForSale(false).WithObjects(new []{"A-2"}).WithAreaPlaces(new(){{"GA1", 7}}).WithCategories(new []{"Cat1"}); + + var events = Client.Events.Create(chartKey, new[] + { + new CreateEventParams().WithForSaleConfig(forSaleConfig1), + new CreateEventParams().WithForSaleConfig(forSaleConfig2) + }); + + Assert.Equivalent(forSaleConfig1, events[0].ForSaleConfig); + Assert.Equivalent(forSaleConfig2, events[1].ForSaleConfig); + } } } \ No newline at end of file diff --git a/SeatsioDotNet.Test/Seasons/CreateSeasonTest.cs b/SeatsioDotNet.Test/Seasons/CreateSeasonTest.cs index 63e5373..0018717 100644 --- a/SeatsioDotNet.Test/Seasons/CreateSeasonTest.cs +++ b/SeatsioDotNet.Test/Seasons/CreateSeasonTest.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using SeatsioDotNet.Charts; using SeatsioDotNet.Events; using Xunit; @@ -68,7 +67,7 @@ public void TableBookingConfigCanBePassedIn() var season = Client.Seasons.Create(chartKey, tableBookingConfig: TableBookingConfig.AllBySeat()); Assert.Equal(TableBookingConfig.AllBySeat().Mode, season.TableBookingConfig.Mode); - } + } [Fact] public void ChannelsCanBePassedIn() @@ -84,5 +83,16 @@ public void ChannelsCanBePassedIn() Assert.Equivalent(channels, season.Channels); } + + [Fact] + public void ForSaleConfigCanBePassedIn() + { + var chartKey = CreateTestChart(); + var forSaleConfig = new ForSaleConfig().WithForSale(false).WithObjects(new []{"A-1"}).WithAreaPlaces(new(){{"GA1", 5}}).WithCategories(new []{"Cat1"}); + + var season = Client.Seasons.Create(chartKey, forSaleConfig: forSaleConfig); + + Assert.Equivalent(forSaleConfig, season.ForSaleConfig); + } } } \ No newline at end of file diff --git a/SeatsioDotNet/Events/CreateEventParams.cs b/SeatsioDotNet/Events/CreateEventParams.cs index f1ffb09..532a63b 100644 --- a/SeatsioDotNet/Events/CreateEventParams.cs +++ b/SeatsioDotNet/Events/CreateEventParams.cs @@ -13,6 +13,7 @@ public class CreateEventParams public Dictionary ObjectCategories { get; set; } public Category[] Categories { get; set; } public List Channels { get; set; } + public ForSaleConfig ForSaleConfig { get; set; } public CreateEventParams WithKey(string key) { @@ -55,5 +56,11 @@ public CreateEventParams WithChannels(List channels) Channels = channels; return this; } + + public CreateEventParams WithForSaleConfig(ForSaleConfig forSaleConfig) + { + ForSaleConfig = forSaleConfig; + return this; + } } } \ No newline at end of file diff --git a/SeatsioDotNet/Events/Events.cs b/SeatsioDotNet/Events/Events.cs index a535cd4..8252f95 100644 --- a/SeatsioDotNet/Events/Events.cs +++ b/SeatsioDotNet/Events/Events.cs @@ -64,6 +64,11 @@ public Event Create(string chartKey, CreateEventParams p) requestBody.Add("channels", p.Channels); } + if (p.ForSaleConfig != null) + { + requestBody.Add("forSaleConfig", p.ForSaleConfig.AsJsonObject()); + } + var restRequest = new RestRequest("/events", Method.Post).AddJsonBody(requestBody); return AssertOk(_restClient.Execute(restRequest)); } @@ -111,6 +116,11 @@ public Event[] Create(string chartKey, CreateEventParams[] eventCreationParams) e.Add("channels", param.Channels); } + if (param.ForSaleConfig != null) + { + e.Add("forSaleConfig", param.ForSaleConfig.AsJsonObject()); + } + events.Add(e); } diff --git a/SeatsioDotNet/Events/ForSaleConfig.cs b/SeatsioDotNet/Events/ForSaleConfig.cs index b40874b..d0e93db 100644 --- a/SeatsioDotNet/Events/ForSaleConfig.cs +++ b/SeatsioDotNet/Events/ForSaleConfig.cs @@ -8,5 +8,40 @@ public class ForSaleConfig public IEnumerable Objects { get; set; } public Dictionary AreaPlaces { get; set; } public IEnumerable Categories { get; set; } + + public ForSaleConfig WithForSale(bool forSale) + { + ForSale = forSale; + return this; + } + + public ForSaleConfig WithObjects(IEnumerable objects) + { + Objects = objects; + return this; + } + + public ForSaleConfig WithAreaPlaces(Dictionary areaPlaces) + { + AreaPlaces = areaPlaces; + return this; + } + + public ForSaleConfig WithCategories(IEnumerable categories) + { + Categories = categories; + return this; + } + + public object AsJsonObject() + { + return new + { + forSale = ForSale, + objects = Objects, + areaPlaces = AreaPlaces, + categories = Categories + }; + } } } \ No newline at end of file diff --git a/SeatsioDotNet/Seasons/Seasons.cs b/SeatsioDotNet/Seasons/Seasons.cs index 85eb41f..e758314 100644 --- a/SeatsioDotNet/Seasons/Seasons.cs +++ b/SeatsioDotNet/Seasons/Seasons.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using RestSharp; using SeatsioDotNet.Events; -using SeatsioDotNet.Util; using static SeatsioDotNet.Util.RestUtil; namespace SeatsioDotNet.Seasons @@ -17,7 +16,7 @@ public Seasons(RestClient restClient, SeatsioClient seatsioClient) _seatsioClient = seatsioClient; } - public Event Create(string chartKey, string key = null, int? numberOfEvents = null, IEnumerable eventKeys = null, TableBookingConfig tableBookingConfig = null, IEnumerable channels = null) + public Event Create(string chartKey, string key = null, int? numberOfEvents = null, IEnumerable eventKeys = null, TableBookingConfig tableBookingConfig = null, IEnumerable channels = null, ForSaleConfig forSaleConfig = null) { Dictionary requestBody = new Dictionary(); requestBody.Add("chartKey", chartKey); @@ -47,6 +46,11 @@ public Event Create(string chartKey, string key = null, int? numberOfEvents = nu requestBody.Add("channels", channels); } + if (forSaleConfig != null) + { + requestBody.Add("forSaleConfig", forSaleConfig.AsJsonObject()); + } + var restRequest = new RestRequest("/seasons", Method.Post).AddJsonBody(requestBody); return AssertOk(_restClient.Execute(restRequest)); }