// TODO: account for results more robustly (esp. insufficient available seats) public static ReserveTicketsResult ReserveTicketsSyos(string sessionKey, int perfId, SyosSeatsPerPriceTypeCollection seatsPerPriceType, SpecialRequests requests) { List<int> priceTypes = new List<int>(); List<int> seatIds = new List<int>(); if (seatsPerPriceType.PriceTypeCount == 1) { priceTypes.Add(seatsPerPriceType[0].PriceTypeId); SyosSeatsPerPriceType spt = seatsPerPriceType[0]; for (int c = 0; c < spt.Count; c++) { seatIds.Add(spt[c]); } } else { foreach (SyosSeatsPerPriceType spt in seatsPerPriceType) { for (int c = 0; c < spt.Count; c++) { priceTypes.Add(spt.PriceTypeId); seatIds.Add(spt[c]); } } } ReserveTicketsResult result = ReserveTicketsResult.Success; int seatsReserved = 0; try { seatsReserved = UnsecureTess.ReserveTicketsSpecifiedSeats( sWebSessionID: Mask(sessionKey), sPriceType: String.Join(",", priceTypes), iPerformanceNumber: perfId, iNumberOfSeats: 0, iZone: 0, sSpecialRequests: Mask(requests), RequestedSeats: String.Join(",", seatIds)); } catch (Exception e) { if (e.Message.Contains("One or more of the selected seats")) { result = ReserveTicketsResult.Unavailable; } else { throw e; } } if (seatsReserved == 0) { result = ReserveTicketsResult.Failed; } else if (seatsReserved < seatIds.Count) { result = ReserveTicketsResult.PartialFailure; } return result; }
private static string Mask(SpecialRequests data) { if (data == null) { return String.Empty; } StringBuilder syntax = new StringBuilder(); bool stringStarted = false; string separator = "&"; if (data.MinContiguousSeats.HasValue) { syntax.Append("ContiguousSeats=" + data.MinContiguousSeats.Value); stringStarted = true; } if (data.NumOfWheelChairSeats.HasValue) { if (stringStarted) { syntax.Append(separator); } else { stringStarted = true; } syntax.Append("WheelChairSeats=" + data.NumOfWheelChairSeats.Value); } if (data.EnsureNoStairs.HasValue) { if (stringStarted) { syntax.Append(separator); } else { stringStarted = true; } char noStairsValue = data.EnsureNoStairs.Value ? 'Y' : 'N'; syntax.Append("NoStairs=" + noStairsValue); } if (data.AislePref.HasValue) { if (stringStarted) { syntax.Append(separator); } else { stringStarted = true; } char aisleValue; switch (data.AislePref.Value) { case AisleSeatPref.ByEitherAisle: aisleValue = 'A'; break; case AisleSeatPref.ByLeftAisle: aisleValue = 'L'; break; case AisleSeatPref.ByRightAisle: aisleValue = 'R'; break; default: // NotByAisle aisleValue = 'N'; break; } syntax.Append("AisleSeat=" + aisleValue); } if (data.StartingPrice.HasValue) { if (stringStarted) { syntax.Append(separator); } else { stringStarted = true; } syntax.Append("StartingPrice=" + data.StartingPrice.Value); } if (data.EndingPrice.HasValue) { if (stringStarted) { syntax.Append(separator); } else { stringStarted = true; } syntax.Append("EndingPrice=" + data.EndingPrice.Value); } if (!String.IsNullOrWhiteSpace(data.StartingRow)) { if (stringStarted) { syntax.Append(separator); } else { stringStarted = true; } syntax.Append("StartingRow=" + data.StartingRow); } if (!String.IsNullOrWhiteSpace(data.EndingRow)) { if (stringStarted) { syntax.Append(separator); } else { stringStarted = true; } syntax.Append("EndingRow=" + data.EndingRow); } if (!String.IsNullOrWhiteSpace(data.StartingSeat)) { if (stringStarted) { syntax.Append(separator); } else { stringStarted = true; } syntax.Append("StartingSeat=" + data.StartingSeat); } if (!String.IsNullOrWhiteSpace(data.EndingSeat)) { if (stringStarted) { syntax.Append(separator); } else { stringStarted = true; } syntax.Append("EndingSeat=" + data.EndingSeat); } if (data.AllowLeaveSingleSeats.HasValue) { if (stringStarted) { syntax.Append(separator); } else { stringStarted = true; } syntax.Append("LeaveSingleSeats=" + (data.AllowLeaveSingleSeats.Value ? "Y" : "N")); } return syntax.ToString(); }
// TODO: Account for failure due to not enough seats being available vs. other circumstances public static ReserveTicketsResult ReserveTickets(string sessionKey, int perfId, int zoneId, SeatsPerPriceTypeCollection seatsPerPriceType, SpecialRequests requests) { List<int> priceTypes = new List<int>(); if (seatsPerPriceType.PriceTypeCount == 1) { priceTypes.Add(seatsPerPriceType[0].PriceTypeId); } else { foreach (SeatsPerPriceType req in seatsPerPriceType) { for (byte s = 0; s < req.NumOfSeats; s++) { priceTypes.Add(req.PriceTypeId); } } } string sPriceTypeValue = String.Join(",", priceTypes); byte numOfSeats = seatsPerPriceType.TotalSeats; int seatsReserved = 0; ReserveTicketsResult result = ReserveTicketsResult.Success; try { seatsReserved = UnsecureTess.ReserveTicketsEx( sWebSessionID: Mask(sessionKey), sPriceType: sPriceTypeValue, iPerformanceNumber: perfId, iNumberOfSeats: numOfSeats, iZone: zoneId, sSpecialRequests: Mask(requests)); } catch (Exception e) { if (e.Message.Contains("Could not find seats")) { result = ReserveTicketsResult.CriteriaNotMet; } else { throw e; } } if (seatsReserved == 0) { result = ReserveTicketsResult.Failed; } else if (seatsReserved < numOfSeats) { throw new ApplicationException( "Ticket reservation encountered an unexpected partial failure."); } return result; }