/// <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); } }
/// <summary> /// Creates a customer in the database /// </summary> /// <param name="customer"></param> /// <returns></returns> public int CreateCustomer(Customer customer) { int affectedRows; dataAccessLayer.BeginTransaction(); try { dataAccessLayer.CreateParameters(7); dataAccessLayer.AddParameters(0, "ID", customer.ID); dataAccessLayer.AddParameters(1, "CustomerName", customer.name); dataAccessLayer.AddParameters(2, "Email", customer.email); dataAccessLayer.AddParameters(3, "Phone", customer.phone); dataAccessLayer.AddParameters(4, "Address", customer.Address); dataAccessLayer.AddParameters(5, "Gender", customer.Gender); dataAccessLayer.AddParameters(6, "Age", customer.Age); affectedRows = dataAccessLayer.ExecuteQuery("spCreateCustomer", CommandType.StoredProcedure); dataAccessLayer.CommitTransaction(); } catch (Exception e) { dataAccessLayer.RollbackTransaction(); Console.WriteLine(e); return(-1); } return(affectedRows); }
public int createShow(Show show) { try { dataAccessLayer.BeginTransaction(); dataAccessLayer.CreateParameters(6); dataAccessLayer.AddParameters(0, "Title", show.title); dataAccessLayer.AddParameters(1, "ImgUrl", show.imgUrl); dataAccessLayer.AddParameters(2, "Hall_ID", show.hall.hallNum); List <string> date_strings = new List <string>(); show.dates.ForEach(d => date_strings.Add(d.ToString("yyyy-MM-dd hh:mm:ss"))); string dates = string.Join(",", date_strings); dataAccessLayer.AddParameters(3, "Dates", dates); dataAccessLayer.AddParameters(4, "basePrice", show.basePrice); dataAccessLayer.AddParameters(5, "description", show.description); int affectedRows = dataAccessLayer.ExecuteQuery("spCreateShow", CommandType.StoredProcedure); dataAccessLayer.CommitTransaction(); return(affectedRows); } catch (Exception e) { dataAccessLayer.RollbackTransaction(); Console.WriteLine(e); return(-1); } }
public int createTheater(Theater theater) { try { dataAccessLayer.BeginTransaction(); dataAccessLayer.CreateParameters(3); dataAccessLayer.AddParameters(0, "Theater", theater.name); dataAccessLayer.AddParameters(1, "Address", theater.address); dataAccessLayer.AddParameters(2, "Active", theater.active); int affectedRows = dataAccessLayer.ExecuteQuery("spCreateTheater", CommandType.StoredProcedure); dataAccessLayer.CommitTransaction(); return(affectedRows); } catch (Exception e) { dataAccessLayer.RollbackTransaction(); Console.WriteLine(e); return(-1); } }
public int createHall(Hall hall) { try { dataAccessLayer.BeginTransaction(); dataAccessLayer.CreateParameters(4); dataAccessLayer.AddParameters(0, "HallNum", hall.hallNum); dataAccessLayer.AddParameters(1, "Theater", hall.theater.name); dataAccessLayer.AddParameters(2, "SeatCount", hall.seats); dataAccessLayer.AddParameters(3, "RowCount", hall.rows); int affectedRows = dataAccessLayer.ExecuteQuery("spCreateHall", CommandType.StoredProcedure); dataAccessLayer.CommitTransaction(); return(affectedRows); } catch (Exception e) { dataAccessLayer.RollbackTransaction(); Console.WriteLine(e); return(-1); } }