/// <summary> /// Creates a new booking /// </summary> /// <param name="booking"></param> /// <returns></returns> public int CreateBooking(Booking booking) { dataAccessLayer.BeginTransaction(); try { decimal basePrice = showDb.getShow(booking.show.ID).basePrice; decimal totalBookingPrice = priceCalculation.calculatePrice(booking, basePrice); dataAccessLayer.CreateParameters(8); dataAccessLayer.AddParameters(0, "CustomerID", booking.customerID); dataAccessLayer.AddParameters(1, "ShowTitle", booking.show.title); dataAccessLayer.AddParameters(2, "BookingDate", booking.date); dataAccessLayer.AddParameters(3, "TheaterName", booking.show.hall.theater.name); dataAccessLayer.AddParameters(4, "SeatStart", booking.seats[0].seat_number); dataAccessLayer.AddParameters(5, "SeatEnd", booking.seats[booking.seats.Count - 1].seat_number); dataAccessLayer.AddParameters(6, "RowNumber", booking.seats[0].row_number); dataAccessLayer.AddParameters(7, "TotalPrice", totalBookingPrice); var customerID = dataAccessLayer.ExecuteScalar("spCreateBooking", CommandType.StoredProcedure); dataAccessLayer.CommitTransaction(); return(int.Parse(customerID.ToString().Trim())); } catch (Exception e) { dataAccessLayer.RollbackTransaction(); Console.WriteLine(e); return(-1); } }