// TODO: consider: is there ever a time to set exceptionOnSessionError to false? /// <summary> /// Gets the cart for the current session, or returns null for an expired cart. /// </summary> /// <param name="exceptionOnSessionError"> /// Whether the method should throw an exception when lacking an authenticated session. /// </param> public static Cart GetCart(bool exceptionOnSessionError) { DataSet cartResults = null; if (!MaintainedSessionExists()) { if (exceptionOnSessionError) // TODO: Check if it's safe to call MaintainTessSession() automatically throw new ApplicationException("GetCart() was called out of sequence. A " + "maintained Tessitura session is required. Try calling " + "MaintainTessSession() first."); } else { try { cartResults = unsecuredClient.GetCart( HttpContext.Current.Session[TessSessionKeySessionKey].ToString()); } catch (Exception exception) { if (exception.Message.Contains("TESSITURA_ACCESS_DENIED_EXCEPTION")) { Logout(); //HttpContext.Current.Response.Redirect("/"); } else if (!exception.Message.Contains("TESSITURA_SEAT_LOCKING_EXCEPTION")) throw exception; } } // if (cartResults != null && cartResults.Tables["Order"] != null // && cartResults.Tables["LineItem"] != null) if (cartResults != null && cartResults.Tables["Order"].Rows.Count > 0) { Cart cart = new Cart(); cart.Id = Convert.ToInt32(cartResults.Tables["Order"].Rows[0]["order_no"]); cart.SeatGroups = new List<CartSeatGroupItem>(); DataRowCollection lineItemResults = cartResults.Tables["LineItem"].Rows; foreach (DataRow lineItemResult in lineItemResults) { CartSeatGroupItem seatGroup = new CartSeatGroupItem(); seatGroup.Id = Convert.ToInt32(lineItemResult["li_seq_no"]); seatGroup.Performance = GetPerformance(Convert.ToInt32(lineItemResult["perf_no"])); seatGroup.SeatingZoneId = Convert.ToInt32(lineItemResult["zone_no"]); seatGroup.SeatingZoneName = null; seatGroup.SeatsPerPriceTypes = new List<CartPriceTypeSeats>(); DataRowCollection subLineItemResults = cartResults.Tables["SubLineItem"].Rows; foreach (DataRow subLineItemResult in subLineItemResults) { if (subLineItemResult["li_seq_no"].ToString()== lineItemResult["li_seq_no"].ToString()) { if (seatGroup.SeatingZoneName == null) { seatGroup.SeatingZoneName = subLineItemResult["zone_desc"].ToString(); } int foundIndex = -1; for (int c = 0; c < seatGroup.SeatsPerPriceTypes.Count; c++) { if (seatGroup.SeatsPerPriceTypes[c].PriceTypeId == Convert.ToInt32(subLineItemResult["price_type"])) { foundIndex = c; break; } } CartPriceTypeSeats priceTypeSeats = new CartPriceTypeSeats(); priceTypeSeats.PriceTypeId =Convert.ToInt32(subLineItemResult["price_type"]); foreach (DataRow priceTypeResult in cartResults.Tables["PriceType"].Rows) { if (Convert.ToInt32(priceTypeResult["price_type"])== priceTypeSeats.PriceTypeId) { priceTypeSeats.PriceTypeName =priceTypeResult["description"].ToString(); priceTypeSeats.PriceTypeIsDefault =Convert.ToChar(priceTypeResult["def_price_type"])== 'Y'; break; } } priceTypeSeats.PricePerSeat = Convert.ToDouble(subLineItemResult["due_amt"]); priceTypeSeats.SeatCount = 1; priceTypeSeats.Seats = new List<CartSeat>(); CartSeat newSeat = new CartSeat(); newSeat.RowIdentifier = subLineItemResult["seat_row"].ToString(); newSeat.SeatNumInRow = Convert.ToInt32(subLineItemResult["seat_num"]); newSeat.Id = Convert.ToInt32(subLineItemResult["seat_no"]); newSeat.Fees = new List<CartFee>(); foreach (DataRow feeResult in cartResults.Tables["SubLineItemFee"].Rows) { if (Convert.ToInt32(subLineItemResult["sli_no"]) == Convert.ToInt32(feeResult["sli_no"])) { newSeat.Fees.Add(new CartFee { Amount = Convert.ToDouble(feeResult["fee_amt"]), Description = feeResult["category_desc"].ToString() }); } } priceTypeSeats.Seats.Add(newSeat); if (foundIndex == -1) { seatGroup.SeatsPerPriceTypes.Add(priceTypeSeats); } else { seatGroup.SeatsPerPriceTypes[foundIndex].Absorb(priceTypeSeats); } } } cart.SeatGroups.Add(seatGroup); } return cart; } else { return null; } }
public void Absorb(CartPriceTypeSeats addition) { SeatCount += addition.SeatCount; foreach (CartSeat newSeat in addition.Seats) { Seats.Add(newSeat); } }